A Complex Check Constraint
567078Jul 18 2007 — edited Jul 20 2007Hi all,
I want to setup a check constraint on the hierarchy table, so that the value of t in table "dg" is the same for both dg1 and dg2. i know we cannot use functions or subqueries inside a constraint. Is there any other way of doing it. thanks in advance for your help.
hierarchy
( dg1 number,
dg2 number)
dg
( d number,
t number);
create or replace function cnt ( p_dg1 number, p_dg2 number) return number is
v_cnt number;
begin
select count(distinct(t))
into v_cnt
from dg
where d in ( p_dg1, p_dg2);
end;
/
alter table hierarchy add constraint chk1 check ( 1 = cnt(hierarchy.dg1, hierarchy.dg2))
/
Thanks
Ram