Oracle:推迟开始/结束块中的约束?

时间:2015-03-16 20:31:27

标签: oracle plsql constraints

如何在开始/结束块内推迟约束?

这有效:

SQL> set constraint t_pk deferred;                                              
Constraint set.

但是相同的语句在开始/结束块中失败:

SQL> begin
2  set constraint t_pk deferred;
3  end;
4  /
set constraint t_pk deferred;
    *
ERROR at line 2:
ORA-06550: line 2, column 5:
PL/SQL: ORA-00922: missing or invalid option
ORA-06550: line 2, column 1:
PL/SQL: SQL Statement ignored

1 个答案:

答案 0 :(得分:6)

您需要使用execute immediate

begin
execute immediate 'set constraint t_pk deferred';
end;