如果(不)满足条件,Oracle SQL将强制列为null
我有一个表如果(不)满足条件,Oracle SQL将强制列为null,sql,oracle,ddl,check-constraints,Sql,Oracle,Ddl,Check Constraints,我有一个表状态: 如果status.status字段的值不是completed alter table status add constraint ck_completion check ( -- status.completiondate's value should be null -- if (Lower(status.status) != 'comp
状态
:
如果status.status
字段的值不是completed
alter table status
add constraint ck_completion
check (
-- status.completiondate's value should be null
-- if (Lower(status.status) != 'complete')
);
因为如果状态不完整或不完整,就不应该有完成日期。如何操作?您可以创建一个表级约束,当状态为“未完成”时,该约束只允许空值,而当状态为“完成”时,该约束允许任何值
alter table status add constraint ck_completion check (
lower(status) = 'complete'
or completiondate is null
)
如果状态为“完成”,则不希望在完成日期接受空值,请尝试以下操作:
alter table status add constraint ck_completion check (
(
lower(status) <> 'complete'
and completiondate is null
)
or (
lower(status) = 'complete'
and completiondate is not null
)
)
alter table status add constraint ck\u completion check(
(
较低(状态)“完成”
并且completiondate为空
)
或(
较低(状态)=“完成”
并且completiondate不为空
)
)
@GurV我们可以做一些类似于默认值的约束吗?