首页 > 代码库 > 【转载】oracle dbms_metadata.get_ddl的使用方法总结
【转载】oracle dbms_metadata.get_ddl的使用方法总结
转自:http://www.jb51.net/article/39715.htm
dbms_metadata.get_ddl()用于获取对象的ddl,其具体用法如下。
注意:在sqlplus里,为了更好的展示DDL,需要设置如下参数:
set line 200
set pagesize 0
set long 99999
set feedback off
set echo off
1)获得表、索引、视图、存储过程、函数的DDL
代码如下:
select dbms_metadata.get_ddl(‘TABLE‘,‘TABLE_NAME‘,‘TABLE_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘INDEX‘,‘INDEX_NAME‘,‘INDEX_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘VIEW‘,‘VIEW_NAME‘,‘VIEW_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘PROCEDURE‘,‘PROCEDURE_NAME‘,‘PROCEDURE_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘FUNCTION‘,‘FUNCTION_NAME‘,‘FUNCTION_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘INDEX‘,‘INDEX_NAME‘,‘INDEX_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘VIEW‘,‘VIEW_NAME‘,‘VIEW_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘PROCEDURE‘,‘PROCEDURE_NAME‘,‘PROCEDURE_OWNER‘) from dual;
select dbms_metadata.get_ddl(‘FUNCTION‘,‘FUNCTION_NAME‘,‘FUNCTION_OWNER‘) from dual;
下面这个脚本用于获得某个schema下所有的表、索引、视图、存储过程、函数的DDL
代码如下:
set pagesize 0
set long 90000
set feedback off
set echo off
spool schema_ddl.sql
SELECT DBMS_METADATA.GET_DDL(‘TABLE‘,u.table_name,u.owner) FROM DBA_TABLES u;
SELECT DBMS_METADATA.GET_DDL(‘VIEW‘,u.view_name,u.owner) FROM DBA_VIEWS u;
SELECT DBMS_METADATA.GET_DDL(‘INDEX‘,u.index_name,u.owner) FROM DBA_INDEXES u;
select dbms_metadata.get_ddl(‘PROCEDURE‘,u.object_name, u.owner,) from dba_objects u where u.object_type = ‘PROCEDURE‘;
select dbms_metadata.get_ddl(‘FUNCTION‘,u.object_name, u.owner,) from dba_objects u where u.object_type = ‘FUNCTION‘;
spool off;
set long 90000
set feedback off
set echo off
spool schema_ddl.sql
SELECT DBMS_METADATA.GET_DDL(‘TABLE‘,u.table_name,u.owner) FROM DBA_TABLES u;
SELECT DBMS_METADATA.GET_DDL(‘VIEW‘,u.view_name,u.owner) FROM DBA_VIEWS u;
SELECT DBMS_METADATA.GET_DDL(‘INDEX‘,u.index_name,u.owner) FROM DBA_INDEXES u;
select dbms_metadata.get_ddl(‘PROCEDURE‘,u.object_name, u.owner,) from dba_objects u where u.object_type = ‘PROCEDURE‘;
select dbms_metadata.get_ddl(‘FUNCTION‘,u.object_name, u.owner,) from dba_objects u where u.object_type = ‘FUNCTION‘;
spool off;
2)获得表空间的DDL
获得单个表空间的DDL:
代码如下:
select dbms_metadata.get_ddl(‘TABLESPACE‘,‘TBS_NAME‘) from dual;
获得所有表空间的DDL:
代码如下:
SELECT DBMS_METADATA.GET_DDL(‘TABLESPACE‘, TS.tablespace_name)
FROM DBA_TABLESPACES TS;
FROM DBA_TABLESPACES TS;
3)获得用户的DDL
获得单个用户的DDL:
代码如下:
select dbms_metadata.get_ddl(‘USER‘,‘EPAY_USER‘) from dual;
4)获得所有用户的DDL
代码如下:
SELECT DBMS_METADATA.GET_DDL(‘USER‘,U.username)
FROM DBA_USERS U;
FROM DBA_USERS U;
【转载】oracle dbms_metadata.get_ddl的使用方法总结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。