隐式游标是否会在PL/SQL中无法关闭?

use*_*452 5 plsql implicit cursor

使用PL/SQL会出现一种情况,例如在异常的情况下,隐式游标将无法关闭?

我知道隐式游标应该在使用后自行关闭,但只是想知道是否存在可能不是这种情况的情况,如果这是可能的,那么什么样的补救将是一个好主意.

Moh*_*ari 2

失败时COMMIT or ROLLBACK游标不会自动关闭
建议使用游标时使用以下路线:

-- before using the cursor
    IF your_cursor %ISOPEN THEN
         CLOSE your_cursor;
    END IF;
   OPEN your_cursor;

-- after using the cursor
         CLOSE your_cursor;
-- when exception
    IF your_cursor %ISOPEN THEN
         CLOSE your_cursor;
    END IF;
Run Code Online (Sandbox Code Playgroud)

  • 但这是使用*显式*游标。OP正在谈论*隐式*游标(`for foo_rec in (select * from foo)loop ...`)。在这种情况下,没有游标变量,也无法使用“%isopen”对其进行测试。 (5认同)