Skip to content

Make DBA Life Easy

  • Home
  • Blog
  • Investment
  • About
  • Contact
  • Disclaimer
  • Subscribe
Make DBA Life Easy

Day: September 30, 2021

dbms_metadata to Generate DDL

The following command is generally used to extract object DDL:

SQL>SELECT DBMS_METADATA.GET_DDL('object_type','object_name','object owner') FROM DUAL;
  • Generate a Table DDL
  • Generate All Tables DDL
  • Generate an Index DDL
  • Generate All Indexes DDL
  • Generate a View DDL
  • Generate All Views DDL
  • Generate a Materialized View DDL
  • Generate All Materialized Views DDL
  • Generate a Procedure DDL
  • Generate All Procedures DDL
  • Generate a Function DDL
  • Generate All Functions DDL
  • Generate a Package DDL
  • Generate a Package Body DDL
  • Generate a Tablespace DDL
  • Generate All Tablespaces DDL
  • Generate Foreign Key Constraints DDL
  • Generate System Privileges Granted to User DDL
  • Generate  the Role Granted to User
  • Generate the Objects Granted to User

Generate a Table DDL

SQL> SELECT DBMS_METADATA.GET_DDL('TABLE','TABLE_NAME','OWNER') FROM DUAL; 

Generate All Tables DDL

SQL> select dbms_metadata.get_ddl('TABLE',t.table_name, t.owner) from dba_tables t where owner='USER_NAME' ;

Generate an Index DDL

SQL> SELECT DBMS_METADATA.GET_DDL('INDEX','INDEX_NAME','OWNER') FROM DUAL;

Generate All Indexes DDL

SQL> select dbms_metadata.get_ddl('INDEX',i.index_name, i.owner) from dba_indexes i where table_owner='USER_NAME' ;

Generate a View DDL

SQL> Select Dbms_metadata.get_ddl ('VIEW', 'VIEW_NAME', 'OWNER') from dual;

Generate All Views DDL

SQL> SELECT dbms_metadata.GET_DDL ('VIEW', v.view_name,v.owner) from dba_views v;

Generate a Materialized View DDL

SQL> SELECT query FROM  DBA_MVIEWS WHERE  MVIEW_NAME='MV_NAME';
SQL> Select Dbms_metadata.get_ddl ('MATERIALIZED_VIEW', 'MVIEW_NAME', 'MV_OWNER') from dual;

Generate All Materialized Views DDL

SQL> SELECT dbms_metadata.GET_DDL ('MATERIALIZED_VIEW', mv.mview_name,mv.owner) from dba_mviews mv;

Generate a Procedure DDL

SQL>select dbms_metadata.get_ddl ('PROCEDURE','PROCEDURE_NAME','OWNER') from dual;

Generate All Procedures DDL

SQL>select dbms_metadata.get_ddl ('PROCEDURE', o.object_name, o.owner,) from dba_objects o where o.object_type = 'PROCEDURE' and o.owner='USER';

Generate a Function DDL

SQL>select dbms_metadata.get_ddl ('FUNCTION', 'FUNCTION_NAME', 'OWNER') from dual;

Generate All Functions DDL

SQL>select dbms_metadata.get_ddl ('FUNCTION', f.object_name, f.owner,) from dba_objects f where f.object_type = 'FUNCTION' and f.owner='USER';

Generate a Package DDL

SQL> SELECT DBMS_METADATA.GET_DDL('PACKAGE','PACKAGE_NAME','OWNER') FROM DUAL;

Generate a Package Body DDL

SQL> SELECT DBMS_METADATA.GET_DDL('PACKAGE_BODY','PACKAGE_NAME','OWNER') FROM DUAL;

Generate a Tablespace DDL

SQL>  SELECT DBMS_METADATA.GET_DDL('TABLESPACE','TABLESPACE_NAME') FROM dual;

Generate All Tablespace DDL

SQL> SELECT dbms_metadata.GET_DDL('TABLESPACE', ts.tablespace_name) from dba_tablespaces ts;

Generate Foreign Key Constraints DDL

SQL> SELECT DBMS_METADATA.GET_DEPENDENT_DDL('REF_CONSTRAINT','TABLE_NAME','OWNER') from dual;

System Privileges Granted to User

SQL> SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','USER') from dual;

Generate Roles Granted DDL

SQL> SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','USER') from dual;

Generate Objects Granted to User DDL

SQL> SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','USER') from dual;
Author dbalifeeasyPosted on September 30, 2021December 10, 2021Categories SQL Scripts For DBATags dbms_metadata, DBMS_METADATA.GET_DDL, DBMS_METADATA.GET_GRANTED_DDL, GET_DEPENDENT_DDLLeave a comment on dbms_metadata to Generate DDL

Google Translate

SEARCH

Calendar

September 2021
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Aug   Oct »

Archives

Blog Stats

  • 992,530 hits

Categories

  • AWS (9)
  • GoldenGate (2)
    • Install and Upgrade (2)
  • Linux (25)
  • MySQL (4)
    • Install and Upgrade (3)
    • Startup and Shutdown (1)
  • Oracle (517)
    • 12c/13c/18c/19c/20x New Features (9)
    • ADR (2)
    • ASM (26)
    • AWR (5)
    • CDB/PDB (18)
    • CHM (14)
    • Client (9)
    • CMU (2)
    • Configuration (24)
    • Corruptions (3)
    • DataGuard (48)
    • DataPump (16)
    • dbms_scheduler (6)
    • Exadata & ExaCC (8)
    • FLASHBACK (2)
    • GI and RAC (109)
    • Globalization (1)
    • Install Upgrade and Patches (63)
    • JAVA (2)
    • Materialized View (7)
    • OEM( Oracle Enterprise Manager) (79)
      • OEM 12c (8)
      • OEM13c (72)
    • ORA- ERRORS (53)
    • oracle advanced compression (4)
    • ORMB (13)
    • Partitioning (12)
    • Performance Tunning (27)
    • RMAN Restore and Recovery (18)
    • Security (9)
    • SQL Net (15)
    • SQL Scripts For DBA (24)
    • TDE (6)
    • TOOLS( AHF TFA ORAchk EXAchk ) (6)
    • TTS (1)
    • User Privileges and Roles (13)
  • PostgreSQL (31)
    • Client (4)
    • Extension (6)
    • Install and Upgrade (8)
    • Migration (4)
    • Objects (4)
    • Performance Tuning (1)
    • Privileges (1)
    • SQL Scripts for DBA (4)
    • Vacuum (4)
  • Premium Content (223)
  • SQL Server (26)
    • Always On (3)
    • Backup and Restore (2)
    • Client (1)
    • Install Patch and Upgrade (4)
    • Security (2)
    • Space (2)
    • SQL Scripts for DBA (6)
    • SSMA (4)
    • Versions (2)
  • VirtualBox (14)
  • Windows (15)

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com
  • Home
  • Blog
  • Investment
  • About
  • Contact
  • Disclaimer
  • Subscribe
Make DBA Life Easy Blog at WordPress.com.
  • Follow Following
    • Make DBA Life Easy
    • Join 52 other followers
    • Already have a WordPress.com account? Log in now.
    • Make DBA Life Easy
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar