Tuesday, August 17, 2010

Generate DDL for any Object using DMS_METADATA Oracle Package


You can get DDL for any object in Oracle Database using the package DBMS_METADATA.get_ddl procedure. Here is an example.

SQL> set serveroutput on;
SQL> DECLARE
  2     dummy                         CLOB;
  3  BEGIN
  4     dummy                      :=
  5                  DBMS_METADATA.get_ddl ('TABLE',        - Object Type
  6                                         'EMP',                        - Table Name
  7                                         'APP_D01'                        - Schema Name
  8                                        );
  9     DBMS_OUTPUT.put_line (DBMS_LOB.SUBSTR (dummy,
 10                                            4000,
 11                                            1
 12                                           ));
 13  END;
 14  /

  CREATE TABLE "APP_D01"."EMP"
   (    "PARAM_NM" VARCHAR2(10) NOT
NULL ENABLE,
        "DESC_TXT" VARCHAR2(50) NOT NULL ENABLE,
        "PARAM_TYP"
VARCHAR2(1) NOT NULL ENABLE,
        "PARAM_VAL" VARCHAR2(80) NOT NULL ENABLE,

CONSTRAINT "EMP_PK" PRIMARY KEY ("PARAM_NM")
  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)
  TABLESPACE "CTS_VSD01"  ENABLE,
         CONSTRAINT
"ATLS_PRM_TYP_CK" CHECK (param_typ in ('V','I','F','B')  ) ENABLE
   ) PCTFREE
10 PCTUSED 70 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)
  TABLESPACE "CTS_VSD01"


PL/SQL procedure successfully completed.

SQL>
Published with Blogger-droid v1.6.8

0 comments:

Post a Comment

 

ORA-BLOG. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com