更通用的解决方案是为选定的表列表转储 DDL sql,但另外还有其他类型的对象。这可以通过使用 all_objects 和 all_users 视图来完成。
对我有用的例子:
select dbms_metadata.GET_DDL(u.object_type,u.object_name, u.owner)
from all_objects u
where 1=1
-- filter only selected object types
and u.object_type in ('TABLE', 'INDEX', 'FUNCTION', 'PROCEDURE', 'VIEW',
'TYPE', 'TRIGGER', 'SEQUENCE')
-- don't want system objects, generated, temp, invalid etc.
and u.object_name not like 'SYS_%'
and temporary!='Y'
and generated!='Y'
and status!='INVALID'
and u.object_name not like 'TMP_%'
and u.object_name not like '%$%'
-- if you want to filter only changed from some date/timestamp:
-- and u.last_ddl_time > '2014-04-02'
-- filter by owner
and owner in (
select username from dba_USERS where DEFAULT_TABLESPACE not like 'SYS%'
and username not in ('ORACLE_OCM')
and username not like '%$%'
)
;
我写了一个python脚本,它基于类似的sql以增量模式刷新db模式:
- runs sql with last_ddl_time>=max(last_ddl_time from last refresh)
- at the end stores last_ddl_time somewhere in filesystem for next refresh
References:
- oracle dbms_metadata.GET_DDL function
- oracle all_objects view