[Oracle] dbms_metadata.get_ddl 的使用方法总结

前端之家收集整理的这篇文章主要介绍了[Oracle] dbms_metadata.get_ddl 的使用方法总结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

dbms_Metadata.get_ddl()用于获取对象的DDL,其具体用法如下。

<FONT style="COLOR: #ff0000">注意:在sqlplus里,为了更好的展示DDL,需要设置如下参数:

<div class="codetitle"><a style="CURSOR: pointer" data="95960" class="copybut" id="copybut95960" onclick="doCopy('code95960')"> 代码如下:
<div class="codebody" id="code95960">
set line 200
set pagesize 0
set long 99999
set Feedback off
set echo off

1)获得表、索引、视图、存储过程、函数的DDL

<div class="codetitle"><a style="CURSOR: pointer" data="87674" class="copybut" id="copybut87674" onclick="doCopy('code87674')"> 代码如下:
<div class="codebody" id="code87674">
select dbms_Metadata.get_ddl('TABLE','TABLE_NAME','TABLEOWNER') from dual;
select dbms
Metadata.get_ddl('INDEX','INDEX_NAME','INDEXOWNER') from dual;
select dbms
Metadata.get_ddl('VIEW','VIEW_NAME','VIEWOWNER') from dual;
select dbms
Metadata.get_ddl('PROCEDURE','PROCEDURE_NAME','PROCEDUREOWNER') from dual;
select dbms
Metadata.get_ddl('FUNCTION','FUNCTION_NAME','FUNCTION_OWNER') from dual;

下面这个脚本用于获得某个schema下所有的表、索引、视图、存储过程、函数的DDL
<div class="codetitle"><a style="CURSOR: pointer" data="65648" class="copybut" id="copybut65648" onclick="doCopy('code65648')"> 代码如下:
<div class="codebody" id="code65648">
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 DBATABLES u;
SELECT DBMS
MetaDATA.GET_DDL('VIEW',u.view_name,u.owner) FROM DBAVIEWS u;
SELECT DBMS
MetaDATA.GET_DDL('INDEX',u.index_name,u.owner) FROM DBAINDEXES u;
select dbms
Metadata.get_ddl('PROCEDURE',u.object_name,u.owner,) from dba_objects u where u.objecttype = 'PROCEDURE';
select dbms
Metadata.get_ddl('FUNCTION',) from dba_objects u where u.object_type = 'FUNCTION';
spool off;

2)获得表空间的DDL

获得单个表空间的DDL:
<div class="codetitle"><a style="CURSOR: pointer" data="5169" class="copybut" id="copybut5169" onclick="doCopy('code5169')"> 代码如下:
<div class="codebody" id="code5169">
select dbms_Metadata.get_ddl('TABLESPACE','TBS_NAME') from dual;

获得所有表空间的DDL:
<div class="codetitle"><a style="CURSOR: pointer" data="86606" class="copybut" id="copybut86606" onclick="doCopy('code86606')"> 代码如下:<div class="codebody" id="code86606">
SELECT DBMS_MetaDATA.GET_DDL('TABLESPACE',TS.tablespace_name)
FROM DBA_TABLESPACES TS;

3)获得用户的DDL

获得单个用户的DDL:
<div class="codetitle"><a style="CURSOR: pointer" data="68852" class="copybut" id="copybut68852" onclick="doCopy('code68852')"> 代码如下:<div class="codebody" id="code68852">
select dbms_Metadata.get_ddl('USER','EPAY_USER') from dual;

获得所有用户的DDL:
<div class="codetitle"><a style="CURSOR: pointer" data="95556" class="copybut" id="copybut95556" onclick="doCopy('code95556')"> 代码如下:<div class="codebody" id="code95556">
SELECT DBMS_MetaDATA.GET_DDL('USER',U.username)
FROM DBA_USERS U;

dbms_metadata.get_ddl

猜你在找的Oracle相关文章