日期:2014-05-16  浏览次数:20986 次

求救,ORACLE 是否可以设置带条件的约束?
求救,ORACLE 是否可以设置带条件的约束?

需求如下:我有一张BD_MESSAGE表(data_type_code,data_url,voucher_no)



当data_type_code='3144' 时,data_url 、voucher_no 不可以重复,当data_type_code 等于 '3143'  ‘3145’时,data_url 、voucher_no 可以重复,





请问该如何设置约束???

------解决方案--------------------
create or replace trigger triggername
  before insert or update on BD_MESSAGE
  for each row
declare
begin
  if (:new.data_type_code = '3144' and :new.data_url = :new.voucher_no) then
    RAISE_APPLICATION_ERROR(-20600, '违反唯一约束!');
  end if;
end;
楼主没说data_type_code是否会等于其他值 所以只需判断3144就可以了