How to generate entire DDL of an Oracle schema (scriptable)? -


can tell me how can generate ddl tables, views, indexes, packages, procedures, functions, triggers, types, sequences, synonyms, grants, etc. inside oracle schema? ideally, copy rows less important.

i want on scheduled job of kind , not manually each time, rules out using wizard in sql developer.

ideally, since running on several schemas have grants , synonyms 1 another, have way find/replace in output schema names match whatever names of new schemas going be.

thanks!

you can spool schema out file via sql*plus , dbms_metadata package. replace schema name 1 via sed. works oracle 10 , higher.

sqlplus<<eof set long 100000 set head off set echo off set pagesize 0 set verify off set feedback off spool schema.out  select dbms_metadata.get_ddl(object_type, object_name, owner) (     --convert dba_objects.object_type dbms_metadata object type:     select         owner,         --java object names may need converted dbms_java.longname.         --that code not included since many database don't have java installed.         object_name,         decode(object_type,             'database link',      'db_link',             'job',                'procobj',             'rule set',           'procobj',             'rule',               'procobj',             'evaluation context', 'procobj',             'package',            'package_spec',             'package body',       'package_body',             'type',               'type_spec',             'type body',          'type_body',             'materialized view',  'materialized_view',             'queue',              'aq_queue',             'java class',         'java_class',             'java type',          'java_type',             'java source',        'java_source',             'java resource',      'java_resource',             object_type         ) object_type     dba_objects      owner in ('owner1')         --these objects included other object types.         , object_type not in ('index partition','index subpartition',            'lob','lob partition','table partition','table subpartition')         --ignore system-generated types support collection processing.         , not (object_type = 'type' , object_name 'sys_plsql_%')         --exclude nested tables, ddl part of parent table.         , (owner, object_name) not in (select owner, table_name dba_nested_tables)         --exlclude overflow segments, ddl part of parent table.         , (owner, object_name) not in (select owner, table_name dba_tables iot_type = 'iot_overflow') ) order owner, object_type, object_name;  spool off quit eof  cat schema.out|sed 's/owner1/myowner/g'>schema.out.change.sql 

put in script , run via cron (scheduler). exporting objects can tricky when advanced features used. don't surprised if need add more exceptions above code.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -