如何判断在 Oracle 事务中是否有未提交的工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/506456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I tell if I have uncommitted work in an Oracle transaction?
提问by cagcowboy
Is there a way to tell if I have uncommitted work (ie DML) in a transaction? Maybe a data-dictionary view I can query?
有没有办法判断我在事务中是否有未提交的工作(即 DML)?也许我可以查询数据字典视图?
A method to find this out both from within and outside of the session running the open transaction would be welcome.
一种从运行开放事务的会话内部和外部找出这一点的方法将是受欢迎的。
Thank you
谢谢
回答by Gary Myers
If you don't have access to v$session you can use
如果您无权访问 v$session,则可以使用
select dbms_transaction.local_transaction_id from dual;
This only works from within the session but doesn't need v$ privileges. If it returns a non-null, you have started a transaction. That normally means uncommitted changes, but there are exceptions. If you issued a savepoint, changed data and rolled back to the savepoint, the transaction still 'lives'. Also, using database links starts transactions, even just for selects (or they used to).
这仅在会话内有效,但不需要 v$ 权限。如果它返回一个非空值,则您已经开始了一个事务。这通常意味着未提交的更改,但也有例外。如果您发出保存点、更改数据并回滚到保存点,则事务仍然“存在”。此外,使用数据库链接启动事务,即使只是用于选择(或他们曾经使用过)。
回答by Quassnoi
SELECT *
FROM v$session v
WHERE v.AUDSID = userenv('sessionid')
AND v.TADDR IS NOT NULL