Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

trace - How can I see queries that are executed against Oracle?

I need to see the queries that are being sent to Oracle to execute them. Can someone give me specific detailed instructions on how to do this ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to see the queries from a specific user, you can use this (assuming you have privileges to query v$session and v$sqlarea (usually through SELECT_CATALOG_ROLE)

SELECT sess.sid,
       sess.username,
       sqla.optimizer_mode,
       sqla.hash_value,
       sqla.address,
       sqla.cpu_time,
       sqla.elapsed_time,
       sqla.sql_text
  FROM v$sqlarea sqla, v$session sess
 WHERE sess.sql_hash_value = sqla.hash_value
   AND sess.sql_address = sqla.address
   AND sess.username = 'SCOTT'

Replace SCOTT with the appropriate username in your system

Output:

 544 SCOTT      ALL_ROWS   2004330732 07000001064088E8         89391       131836 SELECT sess.sid,        sess.username,
                                                                                        sqla.optimizer_mode,        sqla.h
                                                                                  ash_value,        sqla.address,        s
                                                                                  qla.cpu_time,        sqla.elapsed_time,
                                                                                         sqla.sql_text   FROM v$sqlarea sq
                                                                                  la, v$session sess  WHERE sess.sql_hash_
                                                                                  value = sqla.hash_value    AND sess.sql_
                                                                                  address = sqla.address    AND sess.usern
                                                                                  ame = 'SCOTT'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...