oracle 在oracle中打开游标后提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1867046/
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
Commit after opening cursor in oracle
提问by P Sharma
Can anybody suggest, whether we should use commit after opening and before closing cursor?
任何人都可以建议,我们是否应该在打开游标之后和关闭游标之前使用提交?
回答by APC
It is irrelevant in most cases.
在大多数情况下它是无关紧要的。
A cursor is a construct for retrieving data. Once the records have been read it doesn't matter when in the process the cursor is closed, providing it is closed.
游标是用于检索数据的构造。一旦记录被读取,游标在进程中何时关闭并不重要,只要它是关闭的。
The COMMIT should be issued when the transaction is complete and not before.
COMMIT 应该在事务完成时而不是之前发出。
The one case when the order of these two actions matters is when we are executing a CURSOR FOR loop. It is very important that any COMMIT should occur outside of this loop, that is before we open the cursor or after we close it. Otherwise we can have problems with read consistency. There are people who will argue that they have to commit inside the loop for some complicated reasons, but they are almost always mistaken.
这两个操作的顺序很重要的一种情况是我们正在执行 CURSOR FOR 循环。任何 COMMIT 都应该发生在这个循环之外是非常重要的,即在我们打开游标之前或我们关闭它之后。否则我们可能会遇到读取一致性问题。有些人会争辩说由于某些复杂的原因他们必须在循环内提交,但他们几乎总是错误的。
The importance of this last case should not be overestimated. Most transactions should use SQL rather than DML inside a PL/SQL cursor, so it rarely applies.
不应高估最后一个案例的重要性。大多数事务应该在 PL/SQL 游标内使用 SQL 而不是 DML,因此它很少适用。
回答by Tony Andrews
If the cursor locks records using FOR UPDATE, then all locks will be released by the commit. (In fact, any locks held are released by the commit.)
如果游标使用 FOR UPDATE 锁定记录,则提交将释放所有锁定。(实际上,任何持有的锁都由提交释放。)
Also, you are more likely to get an "ORA-01555 Snapshot too old" error due to the "fetch across commit" - see this AskTom thread.
此外,由于“跨提交获取”,您更有可能收到“ORA-01555 快照太旧”错误 - 请参阅此 AskTom 线程。
回答by Pablo Santa Cruz
Well, it depends on what you are trying to accomplish. Sometimes you want to do that, sometimes you don't. Can you specify what are you trying to accomplish?
嗯,这取决于你想要完成什么。有时你想这样做,有时你不想。你能具体说明你想要完成什么吗?