列不为空可延迟

发布于 2024-10-12 07:28:51 字数 516 浏览 2 评论 0原文

在 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);

In Oracle deferred constraints are checked only at the point of commit.

What is the meaning of DEFERRABLE clause in a case of NOT NULL constraint?
For example

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

After these statements I thought the following code would work

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

But it doesn't.

What is the difference between two definitions?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-10-19 07:28:51

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

SET CONSTRAINTS ALL DEFERRED;

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

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

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

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

There are two options here. Either you need to set the constraint to be deferred within the transaction by using the command shown below

SET CONSTRAINTS ALL DEFERRED;

This should be run before doing the UPDATE statement that you have defined.

Alternatively you can set the constraint to be INITIALLY DEFERRED in the table definition

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

After doing either of these things, you should then be able to run the DML that you have in the question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文