Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Last SQL Query for any User
"Alex Smith" <SorryNoSpam_at_Please.Com> wrote in message news:<cl2za.2762$Pz3.1280396_at_news4.srv.hcvlny.cv.net>...
> How can we get the Query that was last executed by a User.
>
> For TOAD users - "Kill / Trace Session" gives this ability to monitor all
> activities and see SQL query executed last for any user.
>
> How can I accomplish this by linking
>
> V$SESSION, V$SQLAREA or V$SQLTEXT
The following probably gives you more than you want, but it may get you started.
select distinct spid,
s.sid, s.serial#,to_char(sysdate - last_call_et/(24*3600),'mm/dd/yyhh24:mi:ss') "LAST_ACTIVITY"
logon_time, osuser, s.program, schemaname, sql_text,
v$process p,
v$sql t,
(select name,sid,value
from v$sesstat st,v$statname n where st.statistic#=n.statistic# and name in('physical reads')) reads, (select name,sid,value from v$sesstat st,v$statname n where st.statistic#=n.statistic# and name in('physical writes')) writes, (select name,sid,value from v$sesstat st,v$statname n where st.statistic#=n.statistic# and name in('CPU used by this session')) cpu where s.paddr=p.addr