I am using Oracle 10g and I want to apply a constraint to a table where the value entered for one column determines whether the other column is NULL or IS NOT NULL. Column 1 may contain only 1 or 0; Column 2 - VARCHAR2 (255).
I know the following works:
CONSTRAINT ck_1 CHECK ((col1=1 AND col2 IS NOT NULL) OR (col1=0 AND col2 IS NULL));
However, I was wondering if it is possible to use CASE to fulfill this restriction and set the NOT NULL attribute to col2, or can CASE be used only to determine values? i.e. something like this work:
CONSTRAINT ck_1 CHECK (CASE WHEN col1=1 THEN col2 IS NOT NULL ELSE col2 IS NULL END);
source share