表table1中就两个字段,id和name,当操作id大于10的时候引发触发器,可提示带有编译错误
create or replace trigger t_on_table1 before insert or update or delete
on table1
for each row
begin
if id>10 then
DBMS_OUTPUT.PUT_LINE('Error!');
end if;
end;
/

解决方案 »

  1.   

    if :new.id > 10 
      

  2.   


    create or replace trigger t_on_table1 before insert or update or delete
    on table1 for each row
    begin
    if updating then
       if :new.id > 10 then
           raise_application_error('-20001','update Error!');
       end if;
    end if;
    if inserting then
       if :new.id > 10 then
           raise_application_error('-20002','insert Error!');
       end if;
    end if;
    if  deleting then
       if :old.id > 10 then
           raise_application_error('-20003','delete Error!');
       end if;
    end if;
    end;
    /
    如上,但是为了说明问题,写的不是最简的方法,自己修改下就可以了。
      

  3.   

    create or replace trigger t_on_table1 before insert or update or delete
    on table1
    for each row
    when (new.id>10)
    BEGIN
      dbms_output.put_line('Error!');
    END;
    /