查找运行中 sql中bind variable value 绑定变量值

2024-07-19 792阅读

Find bind variable value of a SQL that is currently executing (Doc ID 1905278.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 10.1.0.2 to 12.1.0.1 [Release 10.1 to 12.1]

查找运行中 sql中bind variable value 绑定变量值
(图片来源网络,侵删)

Oracle Database Cloud Schema Service - Version N/A and later

Oracle Database Exadata Cloud Machine - Version N/A and later

Oracle Cloud Infrastructure - Database Service - Version N/A and later

Oracle Database Exadata Express Cloud Service - Version N/A and later

Information in this document applies to any platform.

GOAL

 Purpose of this document is to demonstrate how you can find the bind variable values of a SQL that is currently executing.

SOLUTION

 There are two reliable ways to get the bind variable values of a SQL that is currently executing.

1. SQL Monitoring (V$SQL_MONITOR.BINDS_XML)

2. Errorstack Trace

We will look at both of these methods in details.

SQL Monitoring (V$SQL_MONITOR.BINDS_XML)

SQL Monitoring was introduced in 11.1 but the column BIND_XML was added only in 11.2

We run a query with bind variables that takes little longer to complete.

SQL> VAR BIND1 NUMBER;

SQL> EXEC :BIND1:=999;

SQL> select count(*) from DBA_OBJECTS A,DBA_OBJECTS B WHERE A.OBJECT_ID>:BIND1;

While this SQL is still running, we now query v$sql_monitor from a different session.

SQL> select xmltype(binds_xml) from v$sql_monitor where sid =74 and status = 'EXECUTING';

XMLTYPE(BINDS_XML)

------------------------

999

  999

 Note that SQL Monitoring kicks in for SQL statements that run for 5 seconds or more.

ERRORSTACK

Errorstack trace has lot of information in it. In this document, we will focus on the bind variable section of the trace file alone.

This is how you can take an errorstack trace. 12280 is the OS Process ID of the session that runs the SELECT.

connect / as sysdba

oradebug setospid 12280

oradebug unlimit

oradebug dump errorstack 3

oradebug tracefile_name /* This tells you the file name  */

exit

Header section of the trace file shows you the the Current SQL statement text and its SQL ID.

----- Error Stack Dump -----

----- Current SQL Statement for this session (sql_id=9z7qgrmf5at7b) -----

select count(*) from DBA_OBJECTS A,DBA_OBJECTS B WHERE A.OBJECT_ID>:BIND1

...

....

  Now search the trace file with the keyword "Dump Cursor sql_id=9z7qgrmf5at7b". Scroll down a bit and you will see the bind information.

  

----- Bind Info (kkscoacd) -----

Bind#0
oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00

oacflg=03 fl2=1000000 frm=00 csi=00 siz=24 off=0

kxsbbbfp=2b479dde1cc8 bln=22 avl=03 flg=05

value=999

The bind value would be the value seen in "value=" variable. Also note that "oacdty=" would mean the datatype of the bind. Some of the datatype identifiers are 

01 - Char

02 - Number

08 - Long

09 - Varchar

12 - Date

112- CLOB

113- BLOB

114- BFILE

VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]