Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

A Complex Check Constraint

567078Jul 18 2007 — edited Jul 20 2007
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2007
Added on Jul 18 2007
9 comments
2,796 views