tags:

views:

210

answers:

2

I have written the following querry to get the last executed SQL statement in the oracle database for a particular session. The SQL text does not contain the actual value of the bind variables. How to get the bind variable values along with the SQL text.

SELECT * FROM v$SQLTEXT_WITH_NEWLINES WHERE address = 
  (SELECT prev_sql_addr FROM v$session WHERE audsid = userenv('SESSIONID'))
ORDER BY piece;
+1  A: 

Hi varun,

I don't think the bind variables values are stored by default. Not considering the potential security problems (seeing other sessions actual work), the amount of data to store would be massive.

If you want to see the values of the bind variables, you should activate the trace for that session. You would do this by executing the following command in that session:

alter session set events '10046 trace name context forever, level 12';

More information on AskTom: 10046 tracing

Vincent Malgrat
The later versions (10g and 11g) do record the bind variables used for peeking in V$SQL_BIND_capture. But that will only be for the optimization phase of the parse of that SQL, not every execution.
Gary
+1  A: 

To get the bind variables you will have to use the code below, you dont need to use tracing.

SELECT * FROM v$sql_bind_capture WHERE sql_id='';

or

SELECT NAME,POSITION,DATATYPE_STRING,VALUE_STRING 
FROM v$sql_bind_capture WHERE sql_id='';

http://shaharear.blogspot.com/2009/02/find-bind-variable-value.html

Kirit Chandran
+1 http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2114.htmBut STATISTICS_LEVEL server initialization parameter must be above BASIC.
ThinkJet