Use dbms_metadata.get_ddl package to Generate DDL Statements for a different type of Objects in Oracle Database usage as below:
select dbms_metadata.get_ddl('OBJECT_TYPE','OBJECT_NAME','OWNER') from dual; -If you are executing as SYS or SYSTEM
OR
select dbms_metadata.get_ddl('OBJECT_TYPE','OBJECT_NAME') from dual; -If you are already connected with Schema
Examples:
# Generate DDL for all Objects of Schema.
SQL> set feedback off
SQL> set echo off
SQL> set heading 999
SQL> set lines 100
SQL> set long 90000
SQL> select dbms_metadata.GET_DDL(u.object_type,u.object_name,'SCOTT') from dba_objects u where owner = 'SCOTT';
# Generate DDL for Specific Object of Schema.
SQL> set feedback off
SQL> set echo off
SQL> set heading 999
SQL> set lines 100
SQL> set long 90000
SQL> spool DDL_SCOTT_EMP.lst;
SQL> select dbms_metadata.get_ddl('TABLE','EMP','SCOTT') from dual;
DBMS_METADATA.GET_DDL('TABLE','EMP')
--------------------------------------------------------------------------------
CREATE TABLE "SCOTT"."EMP"
( "EMPNO" NUMBER(4,0),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0),
CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")
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 DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ENABLE,
CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
REFERENCES "SCOTT"."DEPT" ("DEPTNO") 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 DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
SQL> spool off;
No comments:
Post a Comment