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