create or replace trigger tri_t1
  before delete on t1 for each row
  declare
 pcount number;
  begin
  select count(*) into pcount where id=:old.id;
if(pcount=0) then
delete from t2 where id=:old.id;
end if;
 end;
上面是触发器代码,请问我该如何改??
使用这句话报错,是触发器里面必须用到,我是删除t1表的一行,如果t1表里只有这一行的话就删除t2表,否则不删除。各位高手,求指教

解决方案 »

  1.   

    select count(*) into pcount where id=:old.id;是写漏了还是特意这么写的?from呢?
      

  2.   


    CREATE OR REPLACE TRIGGER Tri_T11
        BEFORE DELETE ON  T11
        FOR EACH ROW
    DECLARE
      pcount number;
    BEGIN
        select count(*) into pcount  FROM T11 where id = :old.id;
        if(pcount = 0) then
            delete from T12 where id=:old.id;
        END IF;
    END Tri_T11;
    上述代码编译没有问题。
      

  3.   

    如果t1表里只有这一行的话就删除t2表,否则不删除。你表述的是上面这样,但是你的trigger却是:
    如果t1表里不存在要删除的行的话,就删除t2表中的这一行,否则不删除。矛盾啊!