DECLARE cadena VARCHAR(30000); BEGIN FOR registro IN (SELECT DISTINCT LOWER(A.TABLE_NAME) AS TABLE_NAME, LOWER(A.CONSTRAINT_NAME) AS CONSTRAINT_NAME FROM ALL_CONSTRAINTS A, ALL_CONS_COLUMNS C WHERE A.CONSTRAINT_TYPE = 'R' AND A.OWNER = 'USUARIO' AND A.CONSTRAINT_NAME = C.CONSTRAINT_NAME ORDER BY 1,2) LOOP IF SUBSTR(registro.CONSTRAINT_NAME,0,1)='$' THEN cadena := 'ALTER TABLE ' || registro.TABLE_NAME || ' DROP CONSTRAINT "' || registro.CONSTRAINT_NAME || '"'; ELSE cadena := 'ALTER TABLE ' || registro.TABLE_NAME || ' DROP CONSTRAINT ' || registro.CONSTRAINT_NAME; END IF; DBMS_OUTPUT.PUT_LINE(cadena); EXECUTE IMMEDIATE cadena; END LOOP; END;
Nota: es necesario reemplazar la palabra 'USUARIO' por el nombre del usuario.