Saturday 16 July 2022

How to find SQL Text From SID?

How to find SQL Text From Session ID?

The below queries would help you find SQL Text running behind some Oracle SID.


col sql_text form a80
set lines 120
select sql_text from gv$sqltext where hash_value=
(select sql_hash_value from gv$session where sid=&1)
order by piece
/

It will prompt you to enter SID for which you want to find running SQL Query, (here i am entering my own SID so it will show you the same query with provided details)

SQL> SQL> 2 3 4
Enter value for 1: 175 old 2: (select sql_hash_value from gv$session where sid=&1)
new 2: (select sql_hash_value from gv$session where sid=175)

SQL_TEXT
--------------------------------------------------------------------------------
select sql_text from gv$sqltext where hash_value= (select sql_ha
sh_value from gv$session where sid=175) order by piece

2 rows selected.

No comments:

Post a Comment