How to make dbms_metadata.get_ddl more pretty/useful
dbms_metadata.get_dll gets oracle object as xml and next transform it by xslt to ddl script.
List of useful table select table_name from all_tables where table_name like 'META%'
.
METASTYLESHEET - maps a stylesheet to it's name
METAXSL$ - maps an XMLTAG to the stylesheet name - link this to the 1st table
- METAVIEW$ - maps an object type to an XMLTAG - link this to ghe 2nd table
- METAXSLPARAM$ - lookup table for the transform filters available for each object type and transform type.
For a table oracle uses kutable for xml to ddl for a index oracle uses kuindex ... etc.
By setting parameters you can change behavior of transformation. To find useful parameter check METAXSLPARAM$ table or search it in style sheet documents.EMIT_SCHEMA - i have found in kucommon xslt
EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'EMIT_SCHEMA',false); --undocumented remove schemaEXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_CREATION',false); --undocumented remove segement creationEXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS_AS_ALTER',true);select dbms_metadata.get_ddl( object_type => 'TABLE' , name => 'STACKOVERFLOW') from dual;
May I suggest you using expdp / impdp for ddl export purposes.
Export Schema: faydin
with following expdp.
expdp userid=faydin/***** directory=ORA_TMP_DIR reuse_dumpfiles=y content=METADATA_ONLY exclude=STATISTICS schemas=faydin dumpfile=metadata.dmp
Get ddl in ddl.sql
for user : faydin remapped as: faydin3
with impdp
impdp userid=faydin/***** directory=ORA_TMP_DIR dumpfile=metadata.dmp sqlfile=ddl.sql remap_schema=faydin:faydin3
Import schema to db by deleting sqlfile=ddl.sql
phrase in impdp command.