有2个表
table  a   
ship_id  c1  c2 c3  c4 c5 .....
1
2
3
4table  b co1 co2
ship_id
1
2
3
4删除的需求是这样的,删除的时候是通过组合查询删除指定条件的数据
如:delete from a where c1=?  and c2=? and c3=?我的需要是删除了上面sql中a的数据后,同时删除表格b中ship_id=刚才删除的表格a中ship_id的数据

解决方案 »

  1.   

    declare
    v_c1 a.c1%type;
    v_c2 a.c2%type;
    v_c3 a.c3%type;
    begin
    v_c1:=xx;
    v_c2:=xx;
    v_c3:=xx;
     for rec_1 in (select ship_id from a where c1=v_c1 and c2=v_c2 and v3=v_c3) loop
        delete from a where  c1=v_c1 and c2=v_c2 and v3=v_c3;
        delete from b where b.ship_id=rec_1.ship_id;
         end loop;
    commit;
    end;
    /你可以把这个修改成过程,供调用。
      

  2.   

    触发器
    create trigger TGNAME
    after delete on a
    for each row
    begin
    delete from b where ship_id=:old.ship_id;
    end;
      

  3.   

    delete from b where shop_id in (select shop_id from a where c1=? and c2=? and c3=?);delete from a where c1=? and c2=? and c3=?;