Oracle检查约束时的情况

时间:2017-06-06 12:50:33

标签: oracle

在ORACLE中写这样的东西的正确方法是什么?是否可能:

ALTER TABLE REQUESTER ADD CONSTRAINT chk_account_status CHECK   
(CASE WHEN (account_status='R' or account_status='A') THEN   
(email is not null and address is not null and password is not null and mobile_phone is not null) END);

非常感谢任何建议。

谢谢你,
mismas

[编辑]

这就是我现在的表现:

ALTER TABLE REQUESTER ADD CONSTRAINT CK_account_status 
CHECK ((account_status='R' or account_status='A') AND
(email is not null AND MOBILE_PHONE is not null 
AND PASSWORD is not null AND ADDRESS is not null));

1 个答案:

答案 0 :(得分:1)

您不需要CASE,而是需要一些布尔逻辑:

    ( 
        (account_status='R' or account_status='A')
          AND 
        (email is not null and address is not null and password is not null and mobile_phone is not null)
    )     
OR
     not (account_status='R' or account_status='A')

你可以用更紧凑的方式重写它,我使用了这个,因为考虑到你的代码,这是非常不言自明的。