Oracle Database – SQL trace & capturing the value of bind variables

The value of the bind variable has a direct impact on the selectivity of your SQL predicates.  Often it is useful to capture the value of the bind variables to investigate the SQL performance issues.

Here are the steps to capture your Oracle SQL trace file that includes the value of the bind variables.

Alter session set statistics_level=ALL;
Alter session set max_dump_file_size=UNLIMITED;
Alter session set events ‘10046 trace name context forever, level 12‘;

var g_city char(20)

:g_city := ‘Toronto‘;

select * from customers where cust_city = :g_city;

alter session set events ‘10046 trace name context off’;

Open up the trace file and search for string “Bind” and followed by value and of course the value.  Not the prettiest output but it does not the job;

oacdty=96 mxl=128(90) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=1000000 frm=01 csi=873 siz=128 off=0
kxsbbbfp=006061e4  bln=128  avl=30  flg=05

Recall that in Oracle 11g you can provide an identifier for for your trace file to ease the pain of locating the right trace file.