如何在OCI中获取sql_id
有没有办法在调用 OCIStmtExecute()
后获取 sql_id/child number/plan hash?我在 OCIAttrGet()
中看不到它。
注意:作为看不到 v$session
的普通用户 - 如果可以的话,就像执行 select prev_sql_id, prev_child_number from v$session where sid=sys_context('USERENV', 'SID')
谢谢!
Is there a way to get the sql_id/child number/plan hash after calling OCIStmtExecute()
? I can't see it in OCIAttrGet()
.
NOTE: As a regular user who can't see v$session
- if I can it's as simple as executing select prev_sql_id, prev_child_number from v$session where sid=sys_context('USERENV', 'SID')
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法使用 oci 或 sys_context 获取 sql_id 或 plan_hash_value。不过,向 Oracle 支持提交增强请求以添加该功能可能是个好主意。
可以使用以下语句跟踪会话的所有 sql 语句:
根据跟踪级别,生成或多或少的跟踪(级别 4 和 8 创建较少的信息)。要关闭跟踪执行
另一个选项是创建一个函数来自己计算 sql_id
当然,这很容易出错,因为 oracle 将来可能会改变计算 sql_id 的机制。
There is no means to get the sql_id or the plan_hash_value with oci or sys_context. However it might be a good idea to file an enhancement request with oracle support to add that feature.
There is the possibility to trace all sql statements of a session with the following statement:
Depending on the trace level more or less trace is generated (Level 4 and 8 create less information). To turn off the tracing execute
The other option is to create a function to compute the sql_id yourself
Of course this is error prone as oracle might change the mechanism to calculate the sql_id in the future.
以下查询应该有效,但前提是它是您希望识别的语句之后的下一条语句执行。
而且它确实有效......大多数时候。我的客户为 Oracle 12c 编写了一个 PL/SQL 应用程序,并将上述查询放置在执行应用程序查询的代码部分中。他向我展示了输出,显示它有时会返回错误的 prev_child_number 值。我观察了一下,确实无法始终返回正确的数据。在超过 99 次不同的语句执行中,它返回了错误的 prev_child_number 6 次。
我正在寻找导致此查询返回错误数据的现有错误,但尚未找到任何错误。我可能需要在 Oracle 支持下记录新的 SR。
The following query is supposed to work but only if it is the very next statement execution following the one that you wish to identify.
And it does work...most of the time. My customer wrote a PL/SQL application for Oracle 12c and placed the above query in the part of the code that executes the application query. He showed me output that shows that it sometimes returns the wrong value for prev_child_number. I watched and it is indeed failing to always return the correct data. Over 99 distinct statement executions it returned the wrong prev_child_number 6 times.
I am in the process of looking for existing bugs that cause this query to return the wrong data and haven't found any yet. I may have to log a new SR with Oracle support.