请使用sqlplus或者plsql的命令窗口执行语句,如果是plsql,请使用命令窗口,在末尾敲入/,然后回车即可。
1.关闭所有外键
SET SERVEROUTPUT ON SIZE 50000BEGINfor c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R' or CONSTRAINT_TYPE='C') loopDBMS_OUTPUT.PUT_LINE(C.V_SQL);beginEXECUTE IMMEDIATE c.v_sql;exception when others thendbms_output.put_line(sqlerrm);end;end loop;end;
2.开启所有外键
SET SERVEROUTPUT ON SIZE 50000beginfor c in (select 'ALTER TABLE '||TABLE_NAME||' ENABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R' or CONSTRAINT_TYPE='C') loopDBMS_OUTPUT.PUT_LINE(C.V_SQL);beginEXECUTE IMMEDIATE c.v_sql;exception when others thendbms_output.put_line(sqlerrm);end;end loop;end;