oracle 字段非空时唯一的触发器
如题我建了一个简单的表
create table test(id number not null,name varchar2(64),code varchar2(18))
我写了触发器,但没起作用
creater or replace trigger tg_testbefore update of code on test for each rowdeclare cnt number;exp_err exception;beginselect conut(*) into from test where (code is not null) and code=:new.code;if cnt!=0 thenraise exp_err;end if;exceptionwhen exp_err thenraise _application_error(-22222,'重复');end;
执行时查询的那语句就报错了,因为表的字段是可以用空值的,所以不用能约束!