Данные процедуры соответственно отменяют и включают все constraints в схеме
spool dis_cnsr.lst
set serveroutput on
DECLARE
CURSOR user_constr IS
SELECT * FROM USER_CONSTRAINTS
WHERE OWNER='ubc' AND STATUS='ENABLED' AND CONSTRAINT_TYPE IN ('C','R');
row_user_cnstr user_constr%rowtype;
v_cursor NUMBER;
i number;
BEGIN
v_cursor:=DBMS_SQL.open_cursor;
FOR row_user_cnstr IN user_constr LOOP
i:=i+1;
DBMS_OUTPUT.PUT_LINE( i||' - '||row_user_cnstr.constraint_name);
begin
DBMS_SQL.parse(v_cursor,'ALTER TABLE '||row_user_cnstr.table_name
||' DISABLE CONSTRAINTS '||row_user_cnstr.constraint_name,dbms_sql.v7);
COMMIT;
EXCEPTION WHEN others THEN DBMS_OUTPUT.PUT_LINE( 'ups..'||row_user_cnstr.owner
||'.'||row_user_cnstr.table_name);
END;
END LOOP;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
COMMIT;
END;
/
.
exit;
DECLARE
CURSOR user_constr IS
SELECT * FROM USER_CONSTRAINTS
WHERE owner='ubc' AND STATUS='DISABLED'
AND constraint_type IN ('C','R')
AND constraint_name NOT IN ('CHK_DOCPOST_LXQ_LINE#ST#ERR#NO','USER_OPTION$USER_OPTION_AUX') ;
row_user_cnstr user_constr%ROWTYPE;
v_cursor NUMBER;
i number:=0;
BEGIN
v_cursor:=DBMS_SQL.open_cursor;
FOR row_user_cnstr IN user_constr LOOP
i:=i+1;
DBMS_OUTPUT.PUT_LINE( i||' - '||row_user_cnstr.constraint_name);
begin
DBMS_SQL.parse(v_cursor,'ALTER TABLE '||row_user_cnstr.table_name||
' ENABLE CONSTRAINTS '||row_user_cnstr.constraint_name,dbms_sql.v7);
COMMIT;
EXCEPTION WHEN others THEN
DBMS_OUTPUT.PUT_LINE( 'ups..'||row_user_cnstr.owner||'.'||row_user_cnstr.table_name);
END;
END LOOP;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
END;