Oracle: How to find out if there is a transaction pending?

后端 未结 7 1873
太阳男子
太阳男子 2020-11-28 04:34

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,

7条回答
  •  忘掉有多难
    2020-11-28 05:10

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

    SQL> SELECT COUNT(*)
           FROM v$transaction t, v$session s, v$mystat m
          WHERE t.ses_addr = s.saddr
            AND s.sid = m.sid
            AND ROWNUM = 1;
    
      COUNT(*)
    ----------
             0
    
    SQL> insert into a values (1);
    
    1 row inserted
    
    SQL> SELECT COUNT(*)
           FROM v$transaction t, v$session s, v$mystat m
          WHERE t.ses_addr = s.saddr
            AND s.sid = m.sid
            AND ROWNUM = 1;
    
      COUNT(*)
    ----------
             1
    
    SQL> commit;
    
    Commit complete
    
    SQL> SELECT COUNT(*)
           FROM v$transaction t, v$session s, v$mystat m
          WHERE t.ses_addr = s.saddr
            AND s.sid = m.sid
            AND ROWNUM = 1;
    
      COUNT(*)
    ----------
             0
    

提交回复
热议问题