Oracle:如何查明是否有待处理的事务?
我正在寻找一种方法来确定当前会话中是否存在未提交的 INSERT、UPDATE 或 DELETE 语句.一种方法是用当前的 sid 检查 v$lock,但这需要对 v$lock 的读访问,如果 DBA 不想授予它,这是一个问题.任何其他方式(除了跟踪应用程序发出的所有数据库命令)?
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 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)?
推荐答案
您可以检查您的会话是否在 V$TRANSACTION
中有一行(显然这需要对此视图的读取权限):>
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
相关文章