[Oracle] DBMS

Source: Internet
Author: User
The following is a detailed analysis of the use of DBMS_METADATA.GET_DDL in Oracle, the need for friends under the reference

DBMS_METADATA.GET_DDL () is used to get the DDL for the object, as follows.
Note: In Sqlplus, to better demonstrate the DDL, you need to set the following parameters:

Copy Code code as follows:


Set Line 200


Set pagesize 0


Set Long 99999


Set Feedback off


set echo off


1 Get the DDL of Table, index, view, stored procedure, function

Copy Code code as follows:


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;


The following script is used to obtain the DDL of all tables, indexes, views, stored procedures, functions under a schema

Copy Code code as follows:


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 = ' procedu RE ';


Select Dbms_metadata.get_ddl (' function ', U.object_name, U.owner,) from dba_objects u where U.object_type = ' function ';


spool off;


2 Obtain the DDL of the table space
to obtain DDL for a single table space:

Copy Code code as follows:


Select Dbms_metadata.get_ddl (' tablespace ', ' Tbs_name ') from dual;


To obtain DDL for all tablespace:

Copy Code code as follows:


SELECT Dbms_metadata. GET_DDL (' tablespace ', ts.tablespace_name)


from Dba_tablespaces TS;


3 Obtain the user's DDL
to obtain a single user's DDL:

Copy Code code as follows:


Select Dbms_metadata.get_ddl (' USER ', ' Epay_user ') from dual;


To obtain the DDL for all users:

Copy Code code as follows:


SELECT Dbms_metadata. GET_DDL (' USER ', u.username)
From Dba_users U;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.