如何生成Oracle模式的整个DDL(可编写脚本)?

前端之家收集整理的这篇文章主要介绍了如何生成Oracle模式的整个DDL(可编写脚本)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都可以告诉我如何为Oracle模式中的所有表,视图,索引,包,过程,函数,触发器,类型,序列,同义词,授权等生成DDL?理想情况下,我想复制行,但这不太重要。

我想在某种计划的工作这样做,而不是每次手动,所以在sql Developer中排除使用向导。

理想情况下,由于我将在几个模式上运行它们的授权和同义词,我想有一个方法来在输出中做一个find / replace,所以模式名称匹配任何我的新模式的名称成为。

谢谢!

您可以通过sql * Plus和dbms_Metadata包将该模式转储到文件。然后通过sed用另一个模式名称替换模式名称。这适用于Oracle 10和更高版本。
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)
from
(
    --Convert DBA_OBJECTS.OBJECT_TYPE to DBMS_MetaDATA object type:
    select
        owner,--Java object names may need to be converted with DBMS_JAVA.LONGNAME.
        --That code is not included since many database don't have Java installed.
        object_name,decode(object_type,'DATABASE LINK','DB_LINK','JOB','PROCOBJ','RULE SET','RULE','EVALUATION CONTEXT','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
    from dba_objects 
    where owner in ('OWNER1')
        --These objects are included with other object types.
        and object_type not in ('INDEX PARTITION','INDEX SUBPARTITION','LOB','LOB PARTITION','TABLE PARTITION','TABLE SUBPARTITION')
        --Ignore system-generated types that support collection processing.
        and not (object_type = 'TYPE' and object_name like 'SYS_PLsql_%')
        --Exclude nested tables,their DDL is part of their parent table.
        and (owner,object_name) not in (select owner,table_name from dba_nested_tables)
        --Exlclude overflow segments,table_name from dba_tables where iot_type = 'IOT_OVERFLOW')
)
order by owner,object_type,object_name;

spool off
quit
EOF

cat schema.out|sed 's/OWNER1/MYOWNER/g'>schema.out.change.sql

把一切放在一个脚本中,并通过cron(调度程序)运行它。使用高级功能时导出对象可能很棘手。不要惊讶,如果你需要添加一些更多的例外到上面的代码

原文链接:https://www.f2er.com/oracle/207710.html

猜你在找的Oracle相关文章