Komplette Tabellendefintion auslesen

Für Output in der DBMS-Ausgabe erzeugt der folgende Code die komplette Tabellendefinition inkl. Indizes, Kommentare und Grants:

DECLARE
ddl CLOB;
comments CLOB;
grants CLOB;
v_owner VARCHAR2(100) := ‚OWNER_HIER_EINSETZEN‘;
v_table VARCHAR2(100) := ‚TABELLE_HIER_EINSETZEN‘;
BEGIN
SELECT DBMS_METADATA.GET_DDL(‚TABLE‘, t.table_name, t.owner)
INTO ddl
FROM all_tables t
WHERE owner = v_owner AND table_name = v_table;

FOR i IN (SELECT index_name FROM all_indexes WHERE table_owner = v_owner AND table_name = v_table) LOOP
ddl := ddl || CHR(10) || DBMS_METADATA.GET_DDL(‚INDEX‘, i.index_name, ‚MDM‘);
END LOOP;

SELECT DBMS_METADATA.GET_DEPENDENT_DDL(‚COMMENT‘, v_table, v_owner)
INTO comments
FROM dual;

SELECT DBMS_METADATA.GET_DEPENDENT_DDL(‚OBJECT_GRANT‘, v_table, v_owner)
INTO grants
FROM dual;

— Hier können Sie das vollständige DDL-Statement mit Kommentaren und GRANTs ausgeben
DBMS_OUTPUT.PUT_LINE(ddl || CHR(10) || comments || CHR(10) || grants);
END;
/

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert