check constraint for Not null based on some other column value
875608Dec 15 2011 — edited Dec 15 2011Hi 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