views:

39

answers:

2

Hi, 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 ?

A: 

This query will show queries that are currently running:

select sql_text from v$sqlarea where users_executing > 0;

See documentation of V$SQLAREA

Tony Andrews
+4  A: 

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'
bhangm
Excellent, can you give me an example output of that query ? Because I dont have privileges, I asked for the DBA team to give me the output and they basically gave me something that is more like the exectution plan of the query, which is not what I want. Paste a sample output please, so I can know whether demanding permissions would be helpful for me or not
vld_apos
I have a database where I am full admin, but it says v$session does not exist. How do I solve this ?
vld_apos
By full admin do you mean you have the DBA role and are executing the query as the user with this role? If not, then login as SYS and execute GRANT SELECT ON v$session TO <your user>; GRANT SELECT ON v$sqlarea TO <your user>.
bhangm