Maddy
Maddy

Reputation: 3816

Find out last executed query in oracle

I am working with an web based application, Where i have to do some customizations. But i dont have access to Java Source code and even JSP's. I can access only database.

Is there a any way to find out last executed query.

Simply there are many triggers on tables(They fires when i do something from frontend), I want to know which query is causing the trigger to fire. Is there a way to find them. Either inside a trigger or some other oracle views or table.

Upvotes: 0

Views: 3475

Answers (1)

psaraj12
psaraj12

Reputation: 5072

You can use the below example in the trigger to find the statement executed

create or replace TRIGGER tbuTAR_TSM
  BEFORE UPDATE ON TAR_TSM
  FOR EACH ROW
declare
  v_test varchar2(10000);
  cursor c1 is
    select ltrim(sq.sql_text)
      into v_test
      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;
begin
  open c1;
  loop
    fetch c1
      into v_test;
    exit when c1%notfound;
    if substr(upper(v_test), 1, 6) = 'UPDATE' then
      if instr(upper(v_test), 'TAR_TSM') != 0 then
    dbms_output.put_line(v_test);
    exit;
      end if;
    end if;
  end loop;
  close c1;
end;

Upvotes: 2

Related Questions