获取oracle sql语句中绑定变量值的方法

在诊断 sql的性能问题时,我们有时候须要获取其绑定变量的实际值,然后将此实际值带入到sql语句其中,用原来的sql构成select语句(带where条件),实际的运行一下,看一下选择性怎样。

本文就是说获取其绑定变量值的方法。本文的编写得到枯荣长老的帮助,在此表示感谢。

本文适用于与oracle 10G或者更高版本号的db。

alter session set nls_date_format = 'yyyy-mm-dd,hh24:mi:ss';
set linesize 400
col sql_Id format a20
col name format a20
col datatype_string format a14
col value_string format a20
 
--这个sql从内存中读取绑定变量值信息,若是不在内存中,则使用下一个sql
select sql_id,name, datatype_string, last_captured,value_string from v$sql_bind_capture where sql_id='dxfcacn4t4ppw' order by LAST_CAPTURED,POSITION;
 
--这个sql从awr中读取绑定变量值信息
select instance_number,  sql_id,name, datatype_string, last_captured,value_string from dba_hist_sqlbind where sql_id='fahv8x6ngrb50'order by LAST_CAPTURED,POSITION;

原文地址:https://www.cnblogs.com/lcchuguo/p/4082287.html