I need to create a conditional unique constraint on multiple columns using Oracle but I am failing to do so.
Below is what I have right now but it's not working:
Basically, my conditional unique constraint needs to handle a combination of columns under one condition which a = 1.
alter table <table_name> add constraint <constraint_name> unique (<column_1>, <column_2>, a = 1);
I get this error when I run this alter statement:
ORA-00907: missing right parenthesis
a <> 1. Some sample data which shows valid and invalid rows might help someone to help you. - Littlefootais also a field you cant do that in a constraint. - Juan Carlos Oropezaais a column in the same table. If that cannot be done, then how else can I go about this? perhapsunique indexwithcase statements? - samga = 1withcase when a = 1 then 1 else 0 endorcase when a = 1 then 1 end. The first version allows for only one record a=1 and only one record a<>1, the second version is less restrictive - allows for only one record a=1 and multiple records a<>1. - krokodilko