Wednesday, February 21

Viewing bind variable values in 10g

Oracle 10g introduced a couple of new nice views to help tune queries that use bind variables.
One cool view is v$sql_bind_capture, this view hold the latest captured value for each bind variable in queries that has been run.
First have a look in v$sql to find the SQL query you are looking for, join the sql_id to v$sql_bind_capture and to view the bind variable values for that query.
Example:
select
sql_id,
t.sql_text SQL_TEXT,
b.name BIND_NAME,
b.value_string BIND_STRING
from
v$sql t
join v$sql_bind_capture b
using (sql_id)
where
b.value_string is not null
and sql_id='f8pavn1bvsj7t'
/

SQL_TEXT BIND_NAME BIND_STRIN
------------------------------------------- ---------- ----------
select con#,obj#,rcon#,enabled,nvl(defer,0) :1 9110
from cdef$ where robj#=:1
I found a pretty bad example here, an Oracle internal dictionary query, but it should show the point.

3 comments:

Anonymous said...

just what i'm looking for

found you by googling: sql bind variable values

you were ranked # 4 in the search list

thanks man :)

Anonymous said...

Is there any way by whcih we can find out previous bind variable values, like for example I want to see bind variable passed to the query for it's run?

-Thanks,
Jayashree

Anonymous said...

try this one:
http://seilerwerks.wordpress.com/2008/01/29/vsql_bind_capture-not-quite-capturing-sql-binds/
you will a solution:
select name, position, datatype_string, was_captured, value_string,
anydata.accesstimestamp(value_anydata) from v$sql_bind_capture where sql_id = …..