用于删除特定行的PL / SQL过程

时间:2015-10-30 15:21:49

标签: oracle stored-procedures plsql sql-delete data-integrity

尝试创建存储过程以删除分销商提供的所有商品(x)以及我LINE表中对商品的引用。我的问题是总共有3个表。所以我需要先删除LINE表中的引用,然后再删除GOODS表中的项目,我似乎无法正确识别它。我觉得我只是需要一些语法错误的帮助。

CREATE OR REPLACE PROCEDURE PRC_DeleteProd(x IN INTEGER)
AS
    v_dcode    distributor.d_code%type;
    v_gcode    goods.g_code%type;
    v_gcode2   line.g_code%type;

 CURSOR v_delete_cursor IS
   SELECT goods.g_code, line.g_code , d_code
     FROM distributor
     JOIN goods ON (distributor.d_code = goods.g_code)
     JOIN line ON (goods.g_code = line.g_code);

BEGIN

  OPEN v_delete_cursor;

  LOOP
    FETCH v_delete_cursor INTO v_dcode, v_gcode, v_gcode2;
    EXIT WHEN v_cus_cursor%NOTFOUND;

    IF x = v_dcode THEN
      DELETE FROM line WHERE v_gcode2 = x;

      DELETE FROM goods WHERE v_gcode = x;
    END IF;
  END LOOP;
END;
/

1 个答案:

答案 0 :(得分:1)

您没有使用correclty AND关键字

DELETE FROM line
WHERE v_gcode = x
AND
DELETE FROM goods
WHERE v_gcode = x;

应该是

DELETE FROM line
WHERE v_gcode = x;

DELETE FROM goods
WHERE v_gcode = x;