How can I tell if I have uncommitted work in an Oracle transaction?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 18:53:07

问题


Is there a way to tell if I have uncommitted work (ie DML) in a transaction? Maybe a data-dictionary view I can query?

A method to find this out both from within and outside of the session running the open transaction would be welcome.

Thank you


回答1:


SELECT  *
FROM    v$session v
WHERE   v.AUDSID = userenv('sessionid')
    AND v.TADDR IS NOT NULL



回答2:


If you don't have access to v$session you can use

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).



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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!