Unique constraint with conditions?
723980Sep 23 2009 — edited Sep 23 2009Hi all!
I have the following scenario... I need column SERIAL_NUMBER to be UNIQUE constrained but only when column STATUS = 'Y'. SERIAL_NUMBER can be non-unique when STATUS has any other value or is null. So I could en with this:
SERIAL_NUMBER | STATUS
--------------------------------------
123456789 N
123456789 N
123456789 Y
but a new row with 123456789 and 'Y' should not be allowed.
Can this be done with a UNIQUE constraint or do I have to program it in a Trigger? I've been toying with the UNIQUE constraint for a while, but neither DECODE nor WHERE clauses seem to be accepted...
Thanks in advance!