有book及book_copy两个表,要根据book_copy表中的某几个字段删除book表中所有与其相等的记录。
存储过程如下:
CREATE OR REPLACE PROCEDURE PROC_DEL_RECORDS IS
v_cur_records INTEGER := 0;
BEGIN
LOOP
--若表中已无数据,则退出循环
SELECT COUNT(*) INTO v_cur_records FROM book_copy WHERE ROWNUM = 1;
IF v_cur_records = 0 THEN
EXIT;
END IF;
DELETE FROM book WHERE (ID, NAME) IN (SELECT ID, NAME FROM book_copy WHERE ROWNUM < 1000);
DELETE FROM book_copy WHERE ROWNUM < 1000;
COMMIT;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('EXCEPTION OCCURED');
END PROC_DEL_RECORDS;