0

我在想我想在 Postgres 中有一个“延迟检查约束”,但目前显然不支持(Postgres 9.3)

然后我看到甲骨文似乎广泛地“推迟”了它的限制,记录在这里。因此,Oracle 10g+ 是否支持“延迟检查约束”?

相反,我可能错过了进一步的文档,所以我想在这里问一下作为双重检查,相信有些人积极使用 Oracle 会知道答案 - 从而避免反复试验,浪费时间搞乱甲骨文服务器。

4

2 回答 2

2

是的,尽管我不确定您为什么要:

create table t42 (id number,
  constraint check_id check (id > 0) initially deferred deferrable);

table T42 created.

insert into t42 (id) values (-1);

1 rows inserted.

commit;

Error report -
SQL Error: ORA-02091: transaction rolled back
ORA-02290: check constraint (STACKOVERFLOW.CHECK_ID) violated
02091. 00000 -  "transaction rolled back"
*Cause:    Also see error 2092. If the transaction is aborted at a remote
           site then you will only see 2091; if aborted at host then you will
           see 2092 and 2091.
*Action:   Add rollback segment and retry the transaction.

当然,您可以在提交之前对其进行更新:

insert into t42 (id) values (-1);

1 rows inserted.

update t42 set id = 1 where id = -1;

1 rows updated.

commit;

committed.

...但我不确定如果您打算更新它,为什么首先将无效值放在表中。大概在某些情况下这是有用的。

有关文档中的约束延迟的更多信息。

于 2014-02-14T16:19:13.917 回答
1

是的,您可以将约束定义为

"DEFERRABLE" or "NOT DEFERRABLE"

接着

"INITIALLY DEFERRED" or "INITIALLY IMMEDIATE"

例如:

ALTER TABLE T
ADD CONSTRAINT ck_t CHECK (COL_1 > 0)
DEFERRABLE INITIALLY DEFERRED;

查看 Oracle 文档以获取详细信息...

于 2014-02-14T16:16:37.183 回答