[Oracle] dbms_metadata.get_ddl usage Summary

Source: Internet
Author: User

Dbms_metadata.get_ddl () is used to obtain the object DDL. Its usage is as follows.
Note: In sqlplus, the following parameters must be set to better display DDL:
Copy codeThe Code is as follows:
Set line 200
Set pagesize 0
Sets long 99999
Set feedback off
Set echo off

1) DDL for obtaining tables, indexes, views, stored procedures, and functions
Copy codeThe Code is 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 statements of all tables, indexes, views, stored procedures, and functions in a schema.
Copy codeThe Code is as follows:
Set pagesize 0
Sets 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 ('processed', u. object_name, u. owner,) from dba_objects u where u. object_type = 'processed ';
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 tablespace.
Obtain the DDL of a single tablespace:
Copy codeThe Code is as follows:
Select dbms_metadata.get_ddl ('tablespace', 'tbs _ name') from dual;

Obtain the DDL of all tablespaces:
Copy codeThe Code is as follows:
SELECT DBMS_METADATA.GET_DDL ('tablespace', TS. tablespace_name)
FROM DBA_TABLESPACES TS;

3) obtain the user's DDL
Obtain the DDL of a single user:
Copy codeThe Code is as follows:
Select dbms_metadata.get_ddl ('user', 'epay _ user') from dual;

Get the DDL of all users:
Copy codeThe Code is 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.