oracle 为什么 DBMS_MVIEW.REFRESH 有一个隐式提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/828871/
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
Why does DBMS_MVIEW.REFRESH have an implicit commit?
提问by Nick Pierpoint
I noticed recently that calling dbms_mview.refresh(...), which refreshes materialized views in Oracle, has an implicit commit.
我最近注意到调用 dbms_mview.refresh(...),它刷新 Oracle 中的物化视图,有一个隐式提交。
Any ideas - other than "because it does" - why this action has an implicit commit?
任何想法 - 除了“因为它确实” - 为什么这个动作有一个隐式提交?
采纳答案by David
Depending on your Oracle version and/or the parameters you supply dbms_mview.refresh may be doing a TRUNCATE followed by a direct load. TRUNCATE is a DDL command and as such issues an implicit commit. Direct load does not require a commit.
根据您的 Oracle 版本和/或您提供的参数,dbms_mview.refresh 可能会执行 TRUNCATE,然后是直接加载。TRUNCATE 是一个 DDL 命令,因此会发出隐式提交。直接加载不需要提交。
If you are using a more recent version of Oracle, I think 10.2+, you can set the atomic_refresh parameter to TRUE and it will refresh within a single transaction, using standard DELETE / INSERTs. This method could be quite a bit slower though.
如果您使用的是更新版本的 Oracle,我认为是 10.2+,您可以将 atomic_refresh 参数设置为 TRUE,它将使用标准 DELETE/INSERT 在单个事务中刷新。不过,这种方法可能会慢一些。
回答by Leigh Riffel
According to Tom Kyte it is because a decision was made at design time to consider refreshing to be a DDL operation. Since all DDL operations implicitly commit, so does this one. Unfortunatly he doesn't answer the resulting question of why they choose to make it DDL.
根据 Tom Kyte 的说法,这是因为在设计时已决定将刷新视为 DDL 操作。由于所有 DDL 操作都隐式提交,因此也是如此。不幸的是,他没有回答由此产生的问题,即为什么他们选择使其成为 DDL。
回答by tuinstoel
A work arround is to do the call to dbms_mview.refresh in an autonomous transaction (create a PL/SQL procedure with pragma autonomous_transaction).
一个工作是在自治事务中调用 dbms_mview.refresh(创建一个带有 pragma 自治事务的 PL/SQL 过程)。