Oracle: how to formulate a complex constraint with case when

Revious picture Revious · May 23, 2012 · Viewed 11.6k times · Source

The following conditional constraint simply doesn't work. Is it possible to formulate in a working way?

ALTER TABLE eni_trasc_voci_pwr_fatt
ADD CONSTRAINT tvp_constraint_1 CHECK (
CASE WHEN TVP_CODICE_ASSOGGETAMEN = '-' THEN tvp_regione IS NULL
END);

Answer

int2000 picture int2000 · May 23, 2012

Try the following:

ALTER TABLE eni_trasc_voci_pwr_fatt
ADD CONSTRAINT tvp_constraint_1 CHECK (
CASE WHEN TVP_CODICE_ASSOGGETAMEN = '-' THEN tvp_regione else null end IS NULL);