Thanks for the question, Cara.
Asked: October 30, 2015 - 6:19 am UTC
Last updated: October 30, 2015 - 9:48 am UTC
Version: 11.2.0.1.0 - 64bit
Viewed 10K+ times! This question is
You Asked
My database version is "Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production" rac .
My test steps as the followings
Step1
SQL> select * from v$transaction;
no rows selected
SQL> update test set tname='t' where tid=1;
1 row updated.
ps:uncommit
Step2: SQL> select ADDR,start_time from v$transaction;
ADDR START_TIME
---------------- --------------------
000000008F2DFC60 10/30/15 13:33:22
Step3:now i want to query uncommit transction sql;
but i can't find the sql.
if i use 'select SQL_TEXT from v$sql,v$transaction where LAST_ACTIVE_TIME=START_DATe;',
the result is 'select SQL_TEXT from v$sql,v$transaction where LAST_ACTIVE_TIME=START_DATe;
SQL_TEXT
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
update test set tname='t' where tid=1
SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE NO_PARALLEL(SAMPLESUB) opt_param('parallel_execution_enabled', 'false') NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),:"SYS_B_0"), NVL(SUM(C2),:"SYS_B_1") FROM (SELECT /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("TEST") FULL("TEST") NO_PARALLEL_INDEX("TEST") */ :"SYS_B_2" AS C1, CASE WHEN "TEST"."TID"=:"SYS_B_3" THEN :"SYS_B_4" ELSE :"SYS_B_5" END AS C2 FROM "TEST" "TEST") SAMPLESUB
'
the result is not my want,becasue it not only contains the update sql.
if i use 'select gs.SQL_TEXT,
t.start_time,
s.sid,
s.serial#,
s.username,
s.status,
s.schemaname,
s.osuser,
s.process,
s.machine,
s.terminal,
s.program,
s.module,
to_char(s.logon_time, 'DD/MON/YY HH24:MI:SS') logon_time
from gv$transaction t, gv$session s,gv$sql gs
where s.saddr = t.ses_addr
and (s.SQL_ID=gs.SQL_ID or s.PREV_SQL_ID = gs.sql_id)
order by start_time
'
the result is still wrong..
So, is there any sql can help find the uncommit transaction sql ?
and Chris said...
The generic answer is "you can't". There may be situations where you get lucky. You can't count on this however.
If you run selects after your insert/update/deletes in a session then v$session will report these or recursive SQL as you're seeing.
There's also no guarantee that the uncommitted statements are still in the shared pool. This means you can't be certain they're in v$sql. Jonathan Lewis has an example here:
https://jonathanlewis.wordpress.com/2009/04/19/locking-sql/ There's a long discussion about finding the SQL blocking others (a specific isntance of uncommitted SQL) and why you can't guarantee you can find it at:
https://www.freelists.org/post/oracle-l/How-to-find-the-exact-SQL-locking-others
Is this answer out of date? If it is, please let us know via a Comment