Oracle SQL - can CASE be used in a check constraint to determine data attributes?

后端 未结 1 1084
温柔的废话
温柔的废话 2021-01-19 12:14

I\'m using Oracle 10g and I want to apply a constraint to a table where the value entered for one column determines whether another column IS NULL or IS NOT NULL. Column1 ca

相关标签:
1条回答
  • 2021-01-19 12:51

    Since CASE expressions must return a value, and check constraints are boolean, you'll have to compare the result with something, e.g.:

    CONSTRAINT ck_1 CHECK (CASE WHEN col2 IS NOT NULL THEN 1 ELSE 0 END = col1);
    
    0 讨论(0)
提交回复
热议问题