dbms_metadata.get_ddl的用法

FUNCTION get_ddl ( object_type IN VARCHAR2,

name IN VARCHAR2,

schema IN VARCHAR2 DEFAULT NULL,

version IN VARCHAR2 DEFAULT 'COMPATIBLE',

model IN VARCHAR2 DEFAULT 'ORACLE',

transform IN VARCHAR2 DEFAULT 'DDL') RETURN CLOB;

1、从数据字典中获得指定用户下的table和index的DDL脚本

set heading off;

set echo off;

Set pages 999;

set long 90000;

spool d:ddl_list.sql

select dbms_metadata.get_ddl('TABLE','DEPT','SCOTT') from dual; select dbms_metadata.get_ddl('INDEX','DEPT_IDX','SCOTT') from dual;

spool off;

2、从数据字典中获得指定用户下所有table和index的DDL脚本

set pagesize 0 set long 90000

set feedback off

set echo off

spool d:scott_schema.sql

connect scott/tiger;

SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u;

SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name) FROM USER_INDEXES u;

spool off;

摘自:Get table and index DDL the easy way

Don Burleson

http://www.dba-oracle.com/oracle_tips_dbms_metadata.htm

[@more@]
请使用浏览器的分享功能分享到微信等