v$sql_bind_capture與timestamp型別的繫結變數的數值
v$sql_bind_capture與timestamp型別的繫結變數的數值
我們的一個程式(10g)存在一個隱式型別轉換的問題,就是程式中使用timestmp型別,而表的定義為date型別。這樣存在隱式轉換。在查詢v$sql_bind_capture檢視時(10g),一直無法從VALUE_STRING獲取相應數值,顯示為NULL。實際上相關的值也儲存在value_anydata中,如何中value_anydata中抽取呢?(11GR2也存在類似的問題).
google oracle anydata
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/t_anydat.htm
SELECT SQL_ID,NAME, POSITION, datatype_string, max_length, value_string, DUMP (value_anydata), ANYDATA.accesstimestamp (value_anydata)
FROM v$sql_bind_capture a
WHERE a.value_string IS NULL AND a.value_anydata IS NOT NULL AND datatype_string = 'TIMESTAMP'
SQL_ID,NAME,POSITION,DATATYPE_STRING,MAX_LENGTH,VALUE_STRING,DUMP(VALUE_ANYDATA),ANYDATA.ACCESSTIMESTAMP(VALUE_ANYDATA)
5dfmd823r8dsp,:BEGIN_INTERVAL_TIME,4,TIMESTAMP,11,,Typ=58 Len=25: 160,1,140,10,0,0,0,0,248,153,239,49,219,42,0,0,120,40,201,49,219,42,0,0,120,2011-12-13 9:00:20.541000000
5dfmd823r8dsp,:END_INTERVAL_TIME,5,TIMESTAMP,11,,Typ=58 Len=25: 160,1,140,10,0,0,0,0,248,153,239,49,219,42,0,0,120,40,201,49,219,42,0,0,120,2011-12-13 10:00:24.082000000
42cfrr6x5t75c,:B2,3,TIMESTAMP,11,,Typ=58 Len=25: 160,1,140,10,0,0,0,0,248,153,239,49,219,42,0,0,120,40,201,49,219,42,0,0,120,2011-12-13 10:00:24.082000000
實際上如果是其他型別的資料也可以呼叫相應的函式實現。
例子:
1.建立測試表:
SQL> create table t1 as select rownum id ,'test' b from dual connect by level <=10;
Table created.
SQL> create unique index i_t1_id on t1(id);
Index created.
2.
SQL> var a number;
SQL> exec :a := 1;
PL/SQL procedure successfully completed.
SQL> select * from t1 where id= :a;
ID NAME
------------ ----
000001 test
SQL> @dpc
PLAN_TABLE_OUTPUT
--------------------------------------
SQL_ID dyn7rd9t0u9n5, child number 0
-------------------------------------
select * from t1 where id= :a
Plan hash value: 1175136253
--------------------------------------------------------
| Id | Operation | Name | E-Rows |
--------------------------------------------------------
| 0 | SELECT STATEMENT | | |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 |
|* 2 | INDEX UNIQUE SCAN | I_T1_ID | 1 |
--------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=:A)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
39 rows selected.
--也許要執行多次才能capture。
3.
select NAME, POSITION, datatype_string, max_length, value_string,ANYDATA.accessnumber (value_anydata) from v$sql_bind_capture where sql_id='dyn7rd9t0u9n5';
NAME POSITION DATATYPE_STRING MAX_LENGTH VALUE_STRI VA
---------- ---------- ------------------------------ ---------- ---------- ------
:A 1 NUMBER 22 1 1
我們的一個程式(10g)存在一個隱式型別轉換的問題,就是程式中使用timestmp型別,而表的定義為date型別。這樣存在隱式轉換。在查詢v$sql_bind_capture檢視時(10g),一直無法從VALUE_STRING獲取相應數值,顯示為NULL。實際上相關的值也儲存在value_anydata中,如何中value_anydata中抽取呢?(11GR2也存在類似的問題).
google oracle anydata
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/t_anydat.htm
SELECT SQL_ID,NAME, POSITION, datatype_string, max_length, value_string, DUMP (value_anydata), ANYDATA.accesstimestamp (value_anydata)
FROM v$sql_bind_capture a
WHERE a.value_string IS NULL AND a.value_anydata IS NOT NULL AND datatype_string = 'TIMESTAMP'
SQL_ID,NAME,POSITION,DATATYPE_STRING,MAX_LENGTH,VALUE_STRING,DUMP(VALUE_ANYDATA),ANYDATA.ACCESSTIMESTAMP(VALUE_ANYDATA)
5dfmd823r8dsp,:BEGIN_INTERVAL_TIME,4,TIMESTAMP,11,,Typ=58 Len=25: 160,1,140,10,0,0,0,0,248,153,239,49,219,42,0,0,120,40,201,49,219,42,0,0,120,2011-12-13 9:00:20.541000000
5dfmd823r8dsp,:END_INTERVAL_TIME,5,TIMESTAMP,11,,Typ=58 Len=25: 160,1,140,10,0,0,0,0,248,153,239,49,219,42,0,0,120,40,201,49,219,42,0,0,120,2011-12-13 10:00:24.082000000
42cfrr6x5t75c,:B2,3,TIMESTAMP,11,,Typ=58 Len=25: 160,1,140,10,0,0,0,0,248,153,239,49,219,42,0,0,120,40,201,49,219,42,0,0,120,2011-12-13 10:00:24.082000000
實際上如果是其他型別的資料也可以呼叫相應的函式實現。
例子:
1.建立測試表:
SQL> create table t1 as select rownum id ,'test' b from dual connect by level <=10;
Table created.
SQL> create unique index i_t1_id on t1(id);
Index created.
2.
SQL> var a number;
SQL> exec :a := 1;
PL/SQL procedure successfully completed.
SQL> select * from t1 where id= :a;
ID NAME
------------ ----
000001 test
SQL> @dpc
PLAN_TABLE_OUTPUT
--------------------------------------
SQL_ID dyn7rd9t0u9n5, child number 0
-------------------------------------
select * from t1 where id= :a
Plan hash value: 1175136253
--------------------------------------------------------
| Id | Operation | Name | E-Rows |
--------------------------------------------------------
| 0 | SELECT STATEMENT | | |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 |
|* 2 | INDEX UNIQUE SCAN | I_T1_ID | 1 |
--------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=:A)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
39 rows selected.
--也許要執行多次才能capture。
3.
select NAME, POSITION, datatype_string, max_length, value_string,ANYDATA.accessnumber (value_anydata) from v$sql_bind_capture where sql_id='dyn7rd9t0u9n5';
NAME POSITION DATATYPE_STRING MAX_LENGTH VALUE_STRI VA
---------- ---------- ------------------------------ ---------- ---------- ------
:A 1 NUMBER 22 1 1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-713215/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- v$sql_bind_capture 獲取繫結變數SQLAPT變數
- v$sql_bind_capture 獲取繫結變數資訊SQLAPT變數
- 透過v$sql_bind_capture 檢視繫結變數。SQLAPT變數
- 通過v$sql_bind_capture 檢視繫結變數。SQLAPT變數
- 查詢繫結變數的值變數
- SQL*Plus中使用DATE型別的繫結變數SQL型別變數
- 獲取sql繫結變數的值SQL變數
- 關於繫結變數的SQL繫結什麼值變數SQL
- input,select, v-model 繫結的值為數字型別型別
- 如何用FGA得到繫結變數的值變數
- 如何得到繫結變數的輸入值變數
- JavaScript - 變數、值、型別JavaScript變數型別
- ORACLE 獲取繫結變數值Oracle變數
- 如何獲取繫結變數值變數
- Oracle 變數繫結與變數窺視合集Oracle變數
- 繫結變數變數
- cursor_sharing=force強制繫結變數不會把變數值預設當成varchar2型別的理解變數型別
- 繫結變數的測試變數
- 從不繫結變數與繫結變數兩種情況討論柱狀圖的作用變數
- 繫結變數窺測的演變變數
- 【原創】Oracle 變數繫結與變數窺視合集Oracle變數
- V$sql查詢未使用繫結變數的語句SQL變數
- 繫結變數之繫結變數窺探(Bind Peeking)變數
- Oracle 繫結變數Oracle變數
- 繫結變數的一個例子變數
- 繫結變數的使用範圍變數
- oracle繫結變數的測試Oracle變數
- 關於繫結變數的使用變數
- C#變數型別(1):引用型別和值型別 (轉)變數型別
- 分析 JavaScript 的資料型別與變數JavaScript資料型別變數
- 【sql調優】繫結變數與CBOSQL變數
- 淺談變數型別之外的變數命名變數型別
- v$Sql_bind_capture 時間變數無法顯示SQLAPT變數
- 使用繫結變數的一點總結!變數
- c++中的變數型別_C ++中的變數C++變數型別
- js基本語法之 值型別(資料型別)(變數型別)JS資料型別變數
- javascript判斷變數是否是數值型別程式碼JavaScript變數型別
- 通過ERRORSTACK找出正在執行的SQL中的繫結變數值ErrorSQL變數