Sometimes when you don't have access to tools like PL/SQL Developer or any other GUI that can help you see the definition of a certain objects we can use GET_DDL() function from the metadata package DBMS_METADATA.
This article might be very basic for some DBA's but it will for sure help newly comes into DBA's world.
I will start talking about the DBMS_METADATA and the GET_DDL() usage and basic syntax.
DBMS_METADATA - package provides a way for you to retrieve metadata from the database dictionary as XML or creation DDL and to submit the XML to re-create the object.
GET_DDL() - function allow us to extract the creation DDL for an object.
Syntax:
Full Syntax with all arguments and options that can be used:
We can extract the definition of the following objects using GET_DDL function:
TABLE, INDEXES, CONSTRAINT, CONTEXT, DB_LINK, ROLES, DIMENSION, DIRECTORY, FUNCTION, INDEXTYPE, JAVA_SOURCE ,LIBRARY,MATERIALIZED_VIEW, OBJECT_GRANT, PACKAGE,PACKAGE_SPEC,PACKAGE_BODY,PROCEDURE,PROFILE, SEQUENCE, SYNONYM, TRIGGER, USER, VIEW, TYPE_BODY,TYPE, TABLESPACE,...there are few more.
Examples of how we can use the GET_DDL function to extract the object definition:
Note:
while working with sqlplus we need to setup the option set pagesize and long values as bellow.