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!

check constraint for Not null based on some other column value

875608Dec 15 2011 — edited Dec 15 2011
Hi Everyone,

I have a question here:
I want to apply NOT NULL check constraint on a column based on the value in some other column.

ex:
ADD CONSTRAINT sm_ent_cntrct_mstr_chk2 CHECK (
DECODE( pmt_flg,'Y' , pmt_chk_typ_cd IS NOT NULL AND pmt_chk_vndr_nbr IS NOT NULL AND pmt_chk_trm_cd IS NOT NULL) +
DECODE( pmt_flg ,'N', non_pmt_sap_unit_nbr IS NOT NULL AND non_pmt_gl_acct_nbr IS NOT NULL)
);


It means that if the pay_flag = 'Y' then columns pmt_chk_typ_cd , pmt_chk_vndr_nbr and pmt_chk_trm_cd should not be NULL.
Is it even possible to put such a constraint.

I just tried and it didn't work.

Please suggest if anything can be done for this scenario.

Meenakshi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 12 2012
Added on Dec 15 2011
5 comments
2,490 views