日期:2014-05-17  浏览次数:20803 次

触发器实现插入数据前检查con_sex

create or replace trigger con_sex_trigger
before insert on consumer for each row
declare
   ex_con_sex exception;
begin
   if :new.con_sex not in ('m','f') then
    raise ex_con_sex;
   end if;
exception
   when ex_con_sex then
           dbms_output.put_line('con_sex只能是m或者f');
end;

没提示错误,但是没效果。。。   我是新手,求指导

------解决方案--------------------
楼主是这个意思把


create or replace trigger con_sex_trigger
before insert on consumer for each row
declare
begin
   if :new.con_sex not in ('m','f') then
    raise_application_error(-20002,  'con_sex只能是m或者f!!');--异常抛出
   end if;
end;


------解决方案--------------------
引用:
引用:
那是自定义异常,错误号从-20000~-20999一共1000个,自己随意设定。
那是不是raise了自定义异常,就能自动阻止数据插入?


你之前的那段代码也没错,但是你不要处理,就是说你最后一层异常不要再写exception处理了。