Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the last SQL statement executed in Oracle database 11g r2?

I am new to oracle database.

Can someone give me an example of the steps for how to see the last statements executed on the Oracle database 11g r2?

like image 377
teenup Avatar asked Aug 08 '14 13:08

teenup


1 Answers

You can use the below query to get the last sql executed based on last sql which was active in database

select ltrim(sq.sql_text)
  from v$sql sq, v$session se, v$open_cursor oc
 where sq.sql_id = oc.sql_id
   and se.saddr = oc.saddr
   and se.sid = oc.sid
   and se.audsid = SYS_CONTEXT('userenv', 'sessionid')
 order by oc.LAST_SQL_ACTIVE_TIME desc;

You can also use the below to find the last query executed in your session.

  SELECT (SELECT t2.sql_fulltext
    FROM   v$sql t2
    WHERE  t1.prev_sql_id = t2.sql_id
           AND t1.prev_child_number = t2.child_number) sql_fulltext
   FROM   v$session t1
   WHERE  t1.audsid = Sys_context('userenv', 'sessionid'); 
like image 176
psaraj12 Avatar answered Oct 19 '22 19:10

psaraj12