一、批量执行SQL的方式
(1)禁用/启用所有外键
--禁用
SELECT
'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' DISABLE CONSTRAINT ' || CONSTRAINT_NAME || ';'
FROM
SYS.DBA_CONSTRAINTS
WHERE
OWNER NOT LIKE 'SYS%'
AND CONSTRAINT_TYPE = 'R';
--启用
SELECT
'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' ENABLE CONSTRAINT ' || CONSTRAINT_NAME || ';'
FROM
SYS.DBA_CONSTRAINTS
WHERE
OWNER NOT LIKE 'SYS%'
AND CONSTRAINT_TYPE = 'R';
(2)重新编译存储过程
SELECT 'ALTER PROCEDURE '||OWNER||'.'||OBJECT_NAME|| ' COMPILE DEBUG;' FROM SYS.DBA_PROCEDURES WHERE OWNER NOT LIKE 'SYS%';
(3)禁用/启用所有触发器
--禁用
SELECT
'ALTER TRIGGER ' || OWNER || '.' || TRIGGER_NAME || ' DISABLE;'
FROM
SYS.DBA_TRIGGERS
WHERE
OWNER NOT LIKE 'SYS%'
AND TRIGGER_NAME NOT LIKE 'SREF_CON_%';
--启用
SELECT
'ALTER TRIGGER ' || OWNER || '.' || TRIGGER_NAME || ' ENABLE;'
FROM
SYS.DBA_TRIGGERS
WHERE
OWNER NOT LIKE 'SYS%'
AND TRIGGER_NAME NOT LIKE 'SREF_CON_%';
(4)重新编译触发器
SELECT 'ALTER TRIGGER '||OWNER||'.'||TRIGGER_NAME|| ' COMPILE DEBUG;' FROM SYS.DBA_TRIGGERS WHERE OWNER NOT LIKE 'SYS%';
二、会话级别
(1)禁用约束
SET_SESSION_CONS_CHK(0)
(2)禁用触发器
SET_SESSION_TRIGGER_CHECK(0)