【问题标题】:ORA-06511: PL/SQL: cursor already openORA-06511: PL/SQL: 游标已打开
【发布时间】:2017-04-01 00:07:48
【问题描述】:

我正在关闭并在循环外打开游标,但仍然显示错误 .ORA-06511: PL/SQL: cursor already open。任何人都可以检查一下。

/* SQL*Plus prompt variable re-initialize */          
    BEGIN        
    ------------------------my codes------------------    
    OPEN UPD;    
    OPEN SEL;    
    ------------------------end of my codes------------    
    DBMS_OUTPUT.put_line('u2 starts at time: ' || company.sys_ts_fcn);    

    /* Nested block to process UPD; cursor execution failure raises an exception    
       and after exception processing, the loop body resumes for next i counter     value    
       In nested block, add 1 to the d and f columns in each row of table A  */    

    ------------------------my codes------------------       
    --ACCEPT c_retry_count  PROMPT 'Please enter counter value: '    


    ------------------------end of my codes-----------    


    FOR i IN 1 .. c_retry_count LOOP        -- Update cursor retry loop        
      BEGIN       
           u2_try_num := i;  -- Set cursor retry counter to  next loop iteration     number    
              DBMS_OUTPUT.PUT_LINE('Executing table A update in nested block');        
              FOR x_rec in UPD LOOP        
    ------------------------my codes------------------    

              FETCH UPD INTO x_rec;    

              UPDATE A SET D = x_rec.D + 1 , F = x_rec.F + 1 ;    

              EXIT WHEN UPD%NOTFOUND;    

    ------------------------end of my codes------------      
      --      WHERE current of UPD;   
              END LOOP;    

              -- Commit UPD's changes to A rows    
              COMMIT;    
              a_updated := TRUE;       

    ------------------------my codes------------------             
        EXIT;    

    IF a_updated = FALSE THEN     

    RAISE rowsAreLocked ;        

    END IF;            
    ------------------------end of my codes-----------        

      EXCEPTION    
    /*      Returned SQL code and error message values only visible in handlers
            Example: If "ORA-00054: resource busy and acquire with NOWAIT specified" occurs
                    during PL/SQL code execution, above is posted when no handler is
                    defined; otherwise, the above msg is NOT posted, and the EXCEPTION
                     handler is entered so that the event can be dealt with;
                    When this exception section is done, control transfers to the enclosing block
       (which resumes the cursor retry loop) */    
      WHEN rowsAreLocked THEN    
            BEGIN    
    ------------------------my codes------------------    
         DBMS_OUTPUT.put_line (SQLCODE);    
         DBMS_OUTPUT.put_line (SQLERRM);    
         DBMS_OUTPUT.put_line ('error block one');    
         dbms_lock.sleep( 5 );     
    ------------------------end of my codes-----------    
         END;    
      WHEN OTHERS THEN    
            -- Third argument TRUE means: keep error msgs returned from all stack levels    
            raise_application_error(-20001, 'WHEN OTHERS exception occurred', TRUE);          
           DBMS_OUTPUT.put_line ('error block 2');    
      END;     -- Inner block    

    END LOOP;     -- A update retry loop    
    ------------------------my codes------------------        
    CLOSE UPD;    
    ------------------------end of my codes------------    

【问题讨论】:

    标签: oracle


    【解决方案1】:

    在顶部你显式打开UPD

    OPEN UPD;    
    

    然后你有这个:

    FOR x_rec in UPD LOOP        
    

    Cursor FOR loop 隐式打开光标。

    【讨论】:

      【解决方案2】:

      您还没有发布整个程序单元,所以这可能是一个红鲱鱼。

      在代码 sn-p 的开头你打开 UPD 和打开 SEL。但最后你只会关闭。

      【讨论】:

        猜你喜欢
        • 2013-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多