Oracle 通过存储过程删除两个表中符合条件的记录
程序员文章站
2024-04-04 08:23:35
...
有book及book_copy两个表,要根据book_copy表中的某几个字段删除book表中所有与其相等的记录。
有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 DELETE FROM book_copy WHERE ROWNUM
COMMIT;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('EXCEPTION OCCURED');
END PROC_DEL_RECORDS;