Find the corresponding SQL statement using the PID in the operating system, and find the SQL statement using the pid.
In linux, we generally use the TOP command to view the processes with the largest performance consumption. If oracle is used, we need to query the SQL statements currently executed by the process through the process number, baidu has a lot of SQL statements on the Internet. I usually search through the following method: Find the corresponding SQL statement SID through the PID on the operating system:
SELECT s.sid, p.spid FROM v$session s, v$process p WHERE s.paddr = p.addr AND < p.spid = <os pid>
Then, identify the specific content of the corresponding SQL statement through the SID:
SELECT s.sid, s.status, q.sql_text FROM v$session s, v$sqltext q WHERE s.sql_hash_value = q.hash_value AND s.sql_address = q.address AND s.sid = <sid> order by q.piece;
Merge 1
SELECT /*+ ORDERED */ sql_text FROM v$sqltext a WHERE (a.hash_value, a.address) IN ( SELECT DECODE (sql_hash_value, 0, prev_hash_value, sql_hash_value ), DECODE (sql_hash_value, 0, prev_sql_addr, sql_address) FROM v$session b WHERE b.paddr = (SELECT addr FROM v$process c WHERE c.spid = '&pid'))ORDER BY piece ASC/
Merge 2:
Select s.Sid, s.Status, q.Sql_TextFrom V$session s, V$sqltext qWhere s.Sql_Hash_Value = q.Hash_Value And s.Sql_Address = q.Address And s.Sid In (Select s.Sid From V$session s, V$process p Where s.Paddr = p.Addr And p.Spid = '&pid' )Order By q.Piece;