7

在 Oracle 中,延迟约束仅在提交时进行检查。

在 NOT NULL 约束的情况下,DEFERRABLE 子句的含义是什么?例如

create table test(a number not null deferrable, b number);
insert into test(a,b) values (222, 111);
commit;

在这些陈述之后,我认为下面的代码会起作用

update test set a = null where b = 111;
delete test where b = 111;
commit;

但事实并非如此。

两种定义有什么区别?

create table test1(a number not null deferrable, b number);
create table test2(a number not null, b number);
4

1 回答 1

10

这里有两个选项。您需要使用下面显示的命令设置要在事务中延迟的约束

SET CONSTRAINTS ALL DEFERRED;

这应该在执行UPDATE您定义的语句之前运行。

或者,您可以将约束设置INITIALLY DEFERRED在表定义中

create table test(a number not null initially deferred deferrable, b number);

完成上述任一操作后,您应该能够运行问题中的 DML。

于 2011-01-14T10:39:26.387 回答