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

Mar*_*son 2 oracle plsql constraints

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

这有效:

SQL> set constraint t_pk deferred;                                              
Constraint set.
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

Ara*_*llo 6

你需要使用execute immediate:

begin
execute immediate 'set constraint t_pk deferred';
end;
Run Code Online (Sandbox Code Playgroud)