2017-04-01 139 views
1

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

回答

0

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

在代码片段的开始处,您打开UPD和OPEN SEL。但最后你只能关闭UPD。

1

在顶部,你打开UPD明确地

OPEN UPD;  

再后来你有这样的:

FOR x_rec in UPD LOOP   

一个Cursor FOR loop隐含打开游标。