oracle 在10g 时 可以捕获绑定变量并且存到AWR中,但是有诸多不便:
Captured periodically(_cursor_bind_capture_interval), not at real time.
Captured under maximum size(_cursor_bind_capture_area_size)
Only bind variables in WHERE clause are captured
做如下实验来演示如何获取 绑定变量。
sys@ORACL> var bid number;
sys@ORACL> var eid number;
sys@ORACL> exec :bid :=dbms_workload_repository.create_snapshot;
PL/SQL 过程已成功完成。
sys@ORACL> var b1 number;
sys@ORACL> var b2 number;
sys@ORACL> var b3 varchar2(1);
sys@ORACL> begin
2 :b1 :=1;
3 :b2 :=2000;
4 :b3 :='s';
5 end;
6 /
PL/SQL 过程已成功完成。
sys@ORACL> update yang.t set object_name= :b3 where object_id between :b1 and :b2;
已更新119680行。
sys@ORACL> commit;
提交完成。
sys@ORACL> exec :eid :=dbms_workload_repository.create_snapshot;
PL/SQL 过程已成功完成。
sys@ORACL> var sqlid varchar2(100);
sys@ORACL> begin
2 select sql_id into :sqlid
3 from dba_hist_sqltext
4 where sql_text like 'update yang.t%';
5 end;
6 /
PL/SQL 过程已成功完成。
sys@ORACL> print sqlid;
SQLID
--------------------
1bgn2wm9nad9j
sys@ORACL> col name for a10
sys@ORACL> col postion for a99
sys@ORACL> col value_string for a20
sys@ORACL> select snap_id,name,position,value_string,last_captured
2 from dba_hist_sqlbind
3 where sql_id=:sqlid
4 order by snap_id desc;
SNAP_ID NAME POSITION VALUE_STRING LAST_CAPTURED
---------- ---------- ---------- -------------------- --------------
105 :B3 1
105 :B2 3 2000 10-3月 -11
105 :B1 2 1 10-3月 -11