如何提取sql語句中綁定變量的值?

咱們在處理sql語句性能問題時,不少時候,提取到的sql語句帶了綁定變量的,不能直接拿來運行,以下的sql語句,直接執行,會報變量沒有賦值之類的錯誤.sql

SELECT A.RECIPE_ID性能

FROM CIS_OPD_CLINIC A, TABLE(xxx.STR2LIST(:B1 )) B網站

WHERE A.RECIPE_ID = B.COLUMN_VALUEblog

OR A.PARENTID = B.COLUMN_VALUEstring

ORA-01008: 並不是全部變量都綁定.hash

那麼這個B1 具體是什麼值呢?it

立刻查詢v$sqlarea中的sql_idio

SQL> SELECT sql_id, child_number , sql_text FROM v$sql WHERE upper(sql_text) Like '%SELECT A.RECIPE_ID FROM CIS_OPD_CLINIC A, TABLE(xxx.STR2LIST(:B1 )) B WHERE A.RECIPE_ID = B.COLUMN_VALUE OR A.PARENTID = B.COLUMN_VALUE%'變量

2 ;select

SQL_ID CHILD_NUMBER SQL_TEXT

------------- ------------ --------------------------------------------------------------------------------

cn2c9mf5f9xda 0 SELECT sql_id, child_number , sql_text FROM v$sql WHERE upper(sql_text) Like '%

07zdmp13w1zw6 0 SELECT A.RECIPE_ID FROM CIS_OPD_CLINIC A, TABLE(ZLBASE.STR2LIST(:B1 )) B WHERE A

07zdmp13w1zw6 1 SELECT A.RECIPE_ID FROM CIS_OPD_CLINIC A, TABLE(ZLBASE.STR2LIST(:B1 )) B WHERE A

07zdmp13w1zw6 2 SELECT A.RECIPE_ID FROM CIS_OPD_CLINIC A, TABLE(ZLBASE.STR2LIST(:B1 )) B WHERE A

07zdmp13w1zw6 3 SELECT A.RECIPE_ID FROM CIS_OPD_CLINIC A, TABLE(ZLBASE.STR2LIST(:B1 )) B WHERE A

3akum7jd5b8j5 0 SELECT sql_id, child_number , sql_text FROM v$sql WHERE upper(sql_text) Like

bjvppgp4jrfh8 0 SELECT sql_id, child_number , sql_text FROM v$sql WHERE upper(sql_text) Like '

2na7kxsh0msa6 0 select sql_id, address, hash_value, executions, loads, parse_calls, invalidation

8 rows selected

經過如下sql語句察看

SELECT name ,position,datatype_string,was_captured,value_string

FROM v$sql_bind_capture

WHERE sql_id = '&SQLID';

SQL> SELECT name ,position,datatype_string,was_captured,value_string

2 FROM v$sql_bind_capture

3 WHERE sql_id = '&SQLID';

輸入: 07zdmp13w1zw6

SQL>

NAME POSITION DATATYPE_STRING WAS_CAPTURED VALUE_STRING

------------------------------------------------------------ ---------- ------------------------------ ------------ --------------------------------------------------------------------------------

:B1 1 VARCHAR2(2000) NO

:B1 1 VARCHAR2(2000) NO

:B1 1 VARCHAR2(128) NO

:B1 1 VARCHAR2(128) NO

這樣,咱們就已經找到:B1的值,代入原sql中,就能夠正常執行了.

如何提取sql語句中綁定變量的值?

重慶思莊18年4月OCP認證培訓週末班正在授課,歡迎聯繫試聽!新的OCP週末班將於6月2日開課,火熱報名中,名額有限,請提早預約!更多詳情訪問思莊網站諮詢在線客服。

相關文章
相關標籤/搜索