|
-
Primary key using output of function rather than column
I see that we can create indexes on function output instead of column value, and I wonder if we can also do that with PKs..
Basically I have a 2 part PK.. One is based on a number, one is based on whether another column is null or not (only)
So lets say for this data:
1, A
1, null
2, A
2, null
is allowed but this is NOT:
1, A
1, B
nor is this:
1, A
1, null
1, null
How do I make a PK so that it enforces the rule that:
"The combination of col1 and NVL2(col2, 0, 1) is unique"
I've tried:
Code:
ALTER TABLE myTable ADD ( CONSTRAINT myPK UNIQUE (theNumber, NVL2(theLetter, 0, 1)) ENABLE VALIDATE );
But it doesnt seem to work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|