select sid,serial# from v$session where audsid=userenv('sessionid'); --sqlplus下查看当前会话sid
SQL> select s.sid,s.serial#,p.spid from v$session s,v$process p where s.paddr=p.addr and s.sid=42; --已知某个会话的sid
SID SERIAL# SPID
---------- ---------- ------------------------
42 8513 21496 --trace文件号(默认情况下)
execute dbms_system.set_sql_trace_in_session(42,8513,true); --为其他会话打开sql_trace
execute dbms_system.set_sql_trace_in_session(42,8513,false);
exec dbms_monitor.session_trace_enable(42,8513,waits=>true,binds=>true); --10046事件
exec dbms_monitor.session_trace_disable(42,8513);
通过系统进程号反向定位SQL语句
select sql_text from v$sqlarea where hash_value in (select sql_hash_value from v$session s,v$process p where s.paddr=p.addr and p.spid=&pid);
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30373263/viewspace-2119263/
,如需转载,请注明出处,否则将追究法律责任。