[英]Oracle SQL Constraint with IF condition
I need create a constraint with this condition If column_1 = 'Y' then column_2 is not null.我需要用这个条件创建一个约束如果 column_1 = 'Y' 那么 column_2 不是 null。 I need make the column_2 not null if column_1 is equal 'Y'.
如果 column_1 等于“Y”,我需要使 column_2 不是 null。 In other cases you can insert or not values in column_2
在其他情况下,您可以在 column_2 中插入或不插入值
You can express this as:您可以将其表示为:
check (column_1 <> 'Y' or column_2 is not null)
Note: This version assumes that column_1
is not NULL
, but the logic can easily be adjusted to handle that.注意:此版本假定
column_1
不是NULL
,但可以轻松调整逻辑来处理它。
Or, alternatively:或者,或者:
check (not (column_1 = 'Y' and column_2 is null) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.