Home > Database > Mysql Tutorial > body text

Oracle 通过存储过程删除两个表中符合条件的记录

WBOY
Release: 2016-06-07 17:06:02
Original
1237 people have browsed it

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

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template