(извинения за блок кода).
Вот код, который я использовал для решения таких проблем:
PROCEDURE DUMP_CLOB(aCLOB IN CLOB,
hOutput_file IN UTL_FILE.FILE_TYPE) IS
nCLOB_length NUMBER;
nCLOB_offset NUMBER := 1;
nMax_chunk_size NUMBER := 32767;
strChunk VARCHAR2(32767);
BEGIN
nCLOB_length := DBMS_LOB.GETLENGTH(aCLOB);
WHILE nCLOB_offset <= nCLOB_length LOOP
strChunk := DBMS_LOB.SUBSTR(aCLOB, nMax_chunk_size, nCLOB_offset);
UTL_FILE.PUT(hOutput_file, strChunk);
nCLOB_offset := nCLOB_offset + LENGTH(strChunk);
END LOOP;
UTL_FILE.PUT_LINE(hOutput_file, ';');
END DUMP_CLOB;
PROCEDURE DUMP_PRIVS(strOwner IN VARCHAR2,
strObject_name IN VARCHAR2,
hOutput_file IN UTL_FILE.FILE_TYPE) IS
BEGIN
FOR pRow IN (SELECT *
FROM DBA_TAB_PRIVS p
WHERE p.OWNER = strOwner AND
p.TABLE_NAME = strObject_name)
LOOP
UTL_FILE.PUT_LINE(hOutput_file, 'GRANT ' || pRow.PRIVILEGE || ' ON ' ||
strOwner || '.' || strObject_name ||
' TO ' || pRow.GRANTEE || ';');
END LOOP;
END DUMP_PRIVS;
PROCEDURE DUMP_OBJECT(strOwner IN VARCHAR2,
strObject_name IN VARCHAR2,
hOutput_file IN UTL_FILE.FILE_TYPE)
IS
clobDDL CLOB;
strCurr_object_name VARCHAR2(100);
BEGIN
FOR rowObject IN (SELECT *
FROM SYS.DBA_OBJECTS o
WHERE o.OWNER = strOwner AND
o.OBJECT_NAME = strObject_name AND
o.OBJECT_TYPE <> 'TABLE PARTITION')
LOOP
strCurr_object_name := NVL(rowObject.SUBOBJECT_NAME, rowObject.OBJECT_NAME);
UTL_FILE.PUT_LINE(hOutput_file, '-- DDL for ' || LOWER(rowObject.OBJECT_TYPE) || ' ' ||
strOwner || '.' || strCurr_object_name);
SELECT DBMS_METADATA.GET_DDL(rowObject.OBJECT_TYPE, strCurr_object_name, strOwner) AS DDL
INTO clobDDL
FROM DUAL;
DUMP_CLOB(clobDDL, hOutput_file);
DUMP_PRIVS(strOwner, strCurr_object_name, hOutput_file);
IF rowObject.OBJECT_TYPE = 'TABLE' THEN
-- Indexes
FOR aRow IN (SELECT DBMS_METADATA.GET_DDL('INDEX', i.INDEX_NAME, i.OWNER) AS clobIndex
FROM DBA_INDEXES I
WHERE I.TABLE_OWNER = strOwner AND
I.TABLE_NAME = strCurr_object_name)
LOOP
DUMP_CLOB(aRow.clobIndex, hOutput_file);
END LOOP; -- Indexes
END IF;
IF rowObject.OBJECT_TYPE IN ('TABLE', 'VIEW') THEN
-- Triggers
FOR aRow IN (SELECT DBMS_METADATA.GET_DDL('TRIGGER', t.TRIGGER_NAME, t.OWNER) AS clobTrigger
FROM DBA_TRIGGERS t
WHERE TABLE_OWNER = strOwner AND
TABLE_NAME = strCurr_object_name)
LOOP
DUMP_CLOB(aRow.clobTrigger, hOutput_file);
END LOOP; -- Triggers
END IF;
END LOOP;
END DUMP_OBJECT;
PROCEDURE DUMP_OBJECT(strOwner IN VARCHAR2,
strObject_name IN VARCHAR2,
strDirectory_name IN VARCHAR2,
strFilename IN VARCHAR2,
strOpen_mode IN VARCHAR2 DEFAULT 'w')
IS
hOutput_file UTL_FILE.FILE_TYPE;
BEGIN
hOutput_file := UTL_FILE.FOPEN(location => strDirectory_name,
filename => strFilename,
open_mode => strOpen_mode);
DUMP_OBJECT(strOwner, strObject_name, hOutput_file);
UTL_FILE.FCLOSE(hOutput_file);
EXCEPTION
WHEN OTHERS THEN
UTL_FILE.FCLOSE(hOutput_file);
RAISE;
END DUMP_OBJECT;
Я предлагаю поместить эти процедуры в пакет.Позвоните DUMP_OBJECT для вещей, которые вы хотите сбросить.
Поделитесь и наслаждайтесь.