I am trying to add a constraint (in Oracle), that restricts the user from creating an entries having ‘smth’, ‘smth else’ or ‘one more thing’ in a field already exist. Basically, that’s how I would write it:
ALTER TABLE sometable
ADD CONSTRAINT sometable_text_chk
CHECK (
caption IN (
SELECT caption
FROM sometable
WHERE text NOT IN ('smth', 'smth else', 'one more thing')
)
)
Unfortunately, it seems to be not allowed to nest queries for this occasion. Is there perhaps a workaround.
Basically you are trying to have some sort of a general check on the validity of the data in one table based on the data in another table (NOTE: actually probably not, waiting for the OP to clarify his question).
Workaround is either: