ORA-06511:PL / SQL:游标已经打开

时间:2017-04-01 00:07:49

标签: oracle

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

/* 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------------    

2 个答案:

答案 0 :(得分:1)

在顶部,您可以使用

明确打开UPD
OPEN UPD;    

然后你有了这个:

FOR x_rec in UPD LOOP        

Cursor FOR loop隐式打开光标。

答案 1 :(得分:0)

您尚未发布整个程序单元,因此这可能是一个红色的鲱鱼。

在代码段的开头,您打开了UPD和OPEN SEL。但最后你只有CLOSE UPD。

相关问题