{"id":228,"date":"2009-06-15T16:32:08","date_gmt":"2009-06-15T21:32:08","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=228"},"modified":"2011-07-06T09:56:24","modified_gmt":"2011-07-06T14:56:24","slug":"using-vsql_bind_capture","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2009\/06\/15\/using-vsql_bind_capture\/","title":{"rendered":"Using v$sql_bind_capture"},"content":{"rendered":"<p>This is a very useful view in 10g.  When a user came to me with a performance problem, I used to find myself asking, &#8220;What value did you use for the search?&#8221;.  Not very professional, although it could work.  I would also set system 10046 trace and then grep for the problematic SQL (if I knew it) in all trace files created, so I could find a &#8220;bad&#8221; value.<\/p>\n<p>In 10g, some of this has been fixed.  <\/p>\n<p>First, we show an example for a statement that was executed by PL\/SQL&#8230;<\/p>\n<pre lang=\"plsql\" line=\"1\">\r\nSQL> declare\r\n  2    l_num number := 150;\r\n  3    l_name varchar2(30);\r\n  4  begin\r\n  5    select username into l_name from dba_users where user_id = l_num;\r\n  6  end;\r\n  7  \/\r\n\r\nPL\/SQL procedure successfully completed.\r\n\r\nSQL> select sql_id,sql_text from v$sql where sql_text like '%SELECT USERNAME%WHERE USER_ID%';\r\n\r\nSQL_ID\r\n-------------\r\nSQL_TEXT\r\n--------------------------------------------------------------------------------\r\ndgqy15vwrj25q\r\nSELECT USERNAME FROM DBA_USERS WHERE USER_ID = :B1\r\n\r\n7qzmv07r5yzas\r\nselect sql_id,sql_text from v$sql where sql_text like '%SELECT USERNAME%WHERE US\r\nER_ID%'\r\n\r\n\r\nSQL> select sql_id||' -- ' ||value_string from v$sql_bind_capture where sql_id = 'dgqy15vwrj25q';\r\n\r\nSQL_ID||'--'||VALUE_STRING\r\n--------------------------------------------------------------------------------\r\ndgqy15vwrj25q -- 150\r\nSQL><\/pre>\n<p>&#8230;and then another example for one with a host variable&#8230;<\/p>\n<pre lang=\"sql\" line=\"1\">\r\nSQL> variable l_num number\r\nSQL> exec :l_num := 150\r\n\r\nPL\/SQL procedure successfully completed.\r\n\r\nSQL> select \/* fake comment *\/ username from dba_users where user_id = :l_num;\r\n\r\nUSERNAME\r\n------------------------------\r\nCORCACCESS\r\n\r\nSQL> select sql_id,sql_text from v$sql where sql_text like '%fake_comment%';\r\n\r\nSQL_ID\r\n-------------\r\nSQL_TEXT\r\n--------------------------------------------------------------------------------\r\n\r\nf65f9f6xvzj4w\r\nselect \/* fake comment *\/ username from dba_users where user_id = :l_num\r\n\r\n\r\nSQL> select sql_id||' -- ' ||value_string from v$sql_bind_capture where sql_id = 'f65f9f6xvzj4w';\r\n\r\nSQL_ID||'--'||VALUE_STRING\r\n--------------------------------------------------------------------------------\r\nf65f9f6xvzj4w -- 150\r\n\r\nSQL>\r\n<\/pre>\n<p>Binds are captured by default every 15 minutes.  If you need to capture them more frequently, you can set the (undocumented) parameter &#8220;_cursor_bind_capture_interval&#8221;, such as&#8230;<\/p>\n<pre lang=\"sql\" line=\"1\">\r\nalter system set \"_cursor_bind_capture_interval\" = 10; -- capture every ten seconds\r\n<\/pre>\n<p>My understanding is this can have a large impact on system performance, but I haven&#8217;t tested it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a very useful view in 10g. When a user came to me with a performance problem, I used to find myself asking, &#8220;What value did you use for the search?&#8221;. Not very professional, although it could work. I&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2009\/06\/15\/using-vsql_bind_capture\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,22],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/228"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=228"}],"version-history":[{"count":11,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":234,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/228\/revisions\/234"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}