views:

1366

answers:

4

I'm looking for a way to find out if there are uncommited INSERT, UPDATE or DELETE statements in the current session. One way would be to check v$lock with the current sid, but that requires read access to v$lock, which is be a problem if the DBA doesn't want to grant it. Any other ways (other than keeping track of all database commands issued by the application)?

+1  A: 

SELECT * FROM V$TRANSACTION WHERE STATUS='ACTIVE';

See: http://forums.oracle.com/forums/thread.jspa?threadID=691061

Robert Durgin
+4  A: 

Hi ammoQ,

you can check if your session has a row in V$TRANSACTION (obviously that requires read privilege on this view):

SQL> SELECT COUNT(*)
  2    FROM v$transaction t, v$session s, v$mystat m
  3   WHERE t.ses_addr = s.saddr
  4     AND s.sid = m.sid
  5     AND ROWNUM = 1;

  COUNT(*)
----------
         0

SQL> insert into a values (1);

1 row inserted

SQL> SELECT COUNT(*)
  2    FROM v$transaction t, v$session s, v$mystat m
  3   WHERE t.ses_addr = s.saddr
  4     AND s.sid = m.sid
  5     AND ROWNUM = 1;

  COUNT(*)
----------
         1

SQL> commit;

Commit complete

SQL> SELECT COUNT(*)
  2    FROM v$transaction t, v$session s, v$mystat m
  3   WHERE t.ses_addr = s.saddr
  4     AND s.sid = m.sid
  5     AND ROWNUM = 1;

  COUNT(*)
----------
         0
Vincent Malgrat
+1, thanks Vincent that actually came in handy for me just an hour or so ago!
DCookie
+2  A: 

Also see...

http://stackoverflow.com/questions/506456/how-can-i-tell-if-i-have-uncommitted-work-in-an-oracle-transaction

cagcowboy
ooops... I should close my own question for being an "exact duplicate". But I searched for similar quesions before asking, I swear!
ammoQ
:-) Different descriptions... "uncommitted work" vs "pending transaction"
cagcowboy
A: 

This is the query I normally use,

select s.sid
      ,s.serial#
      ,s.username
      ,s.machine
      ,s.status
      ,s.lockwait
      ,t.used_ublk
      ,t.used_urec
      ,t.start_time
from v$transaction t
inner join v$session s on t.addr = s.taddr;
Matthew Watson