v$sql and bind variable

When you see something like

select * from t where x = :1

you may wonder what is :1

Ok, here is a quick join I tested in 10gR2

SQL> var y varchar2(255)
SQL> exec :y:='SCOTT'

PL/SQL procedure successfully completed.

SQL> select job from emp where ename=:y;
JOB
---------
ANALYST

SQL> select sql_text,name,value_string,datatype_string
  2  from v$sql_bind_capture join v$sql using (hash_value)
  3  where sql_text like
  4    'select job from emp where ename=:y%';
SQL_TEXT                              NAME VALUE DATATYPE_STRING
------------------------------------- ---- ----- ---------------
select job from emp where ename=:y    :Y   SCOTT VARCHAR2(2000)

Put your code in <code> and </code> tags

5 Responses to “v$sql and bind variable”

  1. Dominic Says:

    And the fact that the datatype_string is a varchar2(2000) as opposed to varchar2(255) ties into these posts by Jonathan Lewis and Tom Kyte.

  2. Ligarius Says:

    Hi Laurent…

    Very useful!!

    Regards from Santiago , Chile, South America

    http://ligarius.wordpress.com

  3. Coskan Says:

    To keep in mind;
    If you have license to use AWR than the snapshot collections of this view is located in DBA_HIST_SQLBIND view

  4. youngleei Says:

    HI~~

    this is very useful..

    BUT v$sql_bind_capture is available only in 10g.

    in 8i or 9i, How can i get bind variable to use select query?

    please help me.. ^^

  5. Laurent Schneider Says:

    check what Tom Kyte has to say about it
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4254158186083

Leave a Reply

Use <code> and </code> to post code