dbms_metadata.get_ddl的用法

flysky0814發表於2007-09-28

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

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11423276/viewspace-973531/,如需轉載,請註明出處,否則將追究法律責任。