How to get DDL in Oracle
We can get the DDL of an object using GET_DDL()
It is a function of metadata package DBMS_METADATA.
Syntax:
select DBMS_METADATA.GET_DDL(‘TABLE’,'<table_name>’) from DUAL;
Example:
MUDHALVAN@UPGR:SQL> set long 1000
MUDHALVAN@UPGR:SQL> set pagesize 0
MUDHALVAN@UPGR:SQL> select DBMS_METADATA.GET_DDL(‘TABLE’,’EMP’) from DUAL;
Output:
CREATE TABLE “MUDHALVAN”.”EMP”
( “ENO” NUMBER(10,0) NOT NULL ENABLE,
“ENAME” VARCHAR2(20),
“DOB” DATE,
CONSTRAINT “EMP_PK” PRIMARY KEY (“ENO”)
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE “USERS” ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE “USERS”