PL/SQL developer 開發小技能 and ash show command PL/SQL EXECUTE

 

#########sample 0html

---如何在 PL/SQL Block 端查看執行的SQL.sql

The SQL statement within the PL/SQL block is actually stored separately, but you cannot see it because:數據庫

  • every sql statement in a PL/SQL block is stored as capital letters
  • every comment and INTO clause are removed
  • 由於pl/sql 每一個塊都是封裝的,PL/SQL 塊中的每一個 sql 語句都存儲爲大寫字母,因此查看PL/SQL 代碼能夠小寫。
  •  可是在查詢V$SQL 咱們應該去掉into 選項,而且要全部字母要大寫

How to Determine the SQL_ID of a SQL Statement in a PL/SQL Blockapi

 



 

OLUTION

If you have a PL/SQL block such as:oracle

declare v1 number; 
begin 
  select /* SimpleTest */ sum(sal) into v1 from emp; 
end; 
/

Then if you try to find the SQL_ID from v$sql then you will see the SQL_ID of the PL/SQL block NOT the SQL itself:app

SQL> select sql_id, sql_text from v$sql where sql_text like '%SimpleTest%';

SQL_ID        SQL_TEXT
------------- ----------------------------------------------------------------------------------
77hjjr9qgwtzm declare v1 number; begin select /* SimpleTest */ sum(sal) into v1 from emp; end;

The SQL statement within the PL/SQL block is actually stored separately, but you cannot see it because:ide

  • every sql statement in a PL/SQL block is stored as capital letters
  • every comment and INTO clause are removed
  • 由於pl/sql 每一個塊都是封裝的
  • 可是在V$SQL 咱們應該去掉into 選項

Note that optimizer hints are preserved.函數

In other words,工具

select /* SimpleTest */ sum(sal) into v1 from emp

is stored asui

SELECT SUM(SAL) FROM EMP

In order to find it's SQL_ID you would need to search on something similar to the following:

SQL> select sql_id, sql_text from v$sql where sql_text like '%SUM(SAL)%EMP%';

SQL_ID        SQL_TEXT
------------- -------------------------------
5mqhh85sm278a SELECT SUM(SAL) FROM EMP

The SQL_ID can also be determined by using the hash_value from a SQL_TRACE. The hash value can be seen in the raw trace file identified by the "hv=" string.

.................................................
PARSING IN CURSOR #1 len=24 dep=1 uid=54 oct=3 lid=54 tim=1194298465705687 hv=1899044106 ad='997aa660' 
SELECT SUM(SAL) FROM EMP
END OF STMT
..................

In this case the hash value is 1899044106. To find the SQL_ID using the hash value use the following select:

SQL> SELECT sql_id, hash_value, SUBSTR(sql_text,1,40) Text
FROM v$sql
WHERE  hash_value = &Hash_Value; 

SQL_ID        HASH_VALUE SQL_TEXT
------------- ---------- -------------------------------
5mqhh85sm278a 1899044106 SELECT SUM(SAL) FROM EMP

 

 

 

####sample 1

https://www.askmaclean.com/archives/vsqlcommand-sql-opcodes-and-names.html

ash 報告顯示 表明都是存儲過程封裝好的SQL.

V$SQLCOMMAND SQL opcodes and names

47 PL/SQL EXECUTE 
ash 報告顯示 表明都是存儲過程封裝好的SQL. 所以沒法經過AWR和ASH 報告看出,

所以須要進一步查看裏面的查詢 有2個方法,

方法1:使用PL/SQL developer 查看源代碼,爭取從源代碼中找到相關的SQL語句以及表,固然這個比較麻煩,具體能夠查看sample 2



方法2:
經過方法1 查找到的表,進一步須要經過V$sql進一步查看, 查找到SQL,在根據執行次數排序,排序越在前的SQL語句就越多是關鍵語句。

select * from v$sql where sql_text like '%TRAN_AMT%'

 

###sample 2

https://blog.csdn.net/sinat_35512702/article/details/80937840

->經過在PLSQL Developer 中查看存儲過程源碼

https://blog.csdn.net/sinat_35512702/article/details/80937840

->.在Package bobodies 中找到存儲過程所在的包名,好比TOOL,右鍵,選擇Edit Spec & Body

->.以下圖操做,在存儲過程名上按住CTRL鍵  + 右鍵雙擊

 

1.在Package bobodies 中找到存儲過程所在的包名,好比TOOL,右鍵,選擇Edit Spec & Body

  

2.找到你要查看的存儲過程,點擊一下

3.以下圖操做,在存儲過程名上按住CTRL鍵  + 右鍵雙擊

4.該存儲過程源碼就能夠看見了

 

 

 

 

 

##########sample 3:

https://blog.csdn.net/zjxbllg2008/article/details/82380812

手工查看存儲過程的包含的關鍵字

oracle

##for

select * from all_source t where type = 'PROCEDURE' and text like '%mainacc%'
select * from all_source t where type = 'FUNCTION' and text like '%mainacc%'
select * from all_source t where type = 'PACKAGE BODY' and text like '%mainacc%'

 

查找存儲過程

1

select t.name,t.text from all_source t where type = 'PROCEDURE' and text like '%var_app_1_pst%'

查找函數

1

select t.name,t.text from all_source t where type = 'FUNCTION' and text like '%var_app_1_pst%'

MSSQL

1

2

3

4

select b.name

from 數據庫名.dbo.syscomments a, 數據庫名.dbo.sysobjects b

where a.id=b.id  and b.xtype='p' and a.text like '%key words%'

order by name

 

Oracle中,若是關鍵字是一張表的話,還能夠經過表的Referenced by屬性找到相關的函數、存儲過程和觸發器等。

如:

MSSQL相似。

 

oracle數據庫中如何查看已經建立的索引信息

1. 根據表名,查詢一張表的索引

1

select from user_indexes where table_name=upper('表名');

2. 根據索引號,查詢表索引字段

1

select from user_ind_columns where index_name=('索引名');

3.根據索引名,查詢建立索引的語句

1

select dbms_metadata.get_ddl('INDEX','索引名', ['用戶名']) from dual ; --['用戶名']可省,默認爲登陸用戶

PS:dbms_metadata.get_ddl還能夠獲得建表語句,如:

1

2

SELECT DBMS_METADATA.GET_DDL('TABLE','表名', ['用戶名']) FROM DUAL ; //取單個表的建表語句,['用戶名']可不輸入,默認爲登陸用戶

SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u; //取用戶下全部表的建表語句

固然,也能夠用pl/sql developer工具來查看相關的表的各類信息。

相關文章
相關標籤/搜索