Reputation: 1623
IN SQL Server there is a tasks feature and then you can 'generate scripts' which is useful for things like views and stored procedures, or more.
In Oracle, can I generate such a copy of Views? How is this done? I am using PL SQL.
I am trying to update my Oracle database on my laptop. REcently many new views and stored procedures were added to the database I am working on at job. I also work from laptop for development.
Rather than backup the entire database, if I can just copy these views and sp's would be far easier.
Upvotes: 0
Views: 729
Reputation: 231661
It sounds like you are probably looking for the DBMS_METADATA
package and the GET_xxx
functions within that package. This is what tools like SQL Developer and other GUIs will call to generate the DDL for a particular object.
So, for example, if you wanted to get the DDL for the EMP
table in the SCOTT
schema in SQL (or PL/SQL), you can
SQL> ed
Wrote file afiedt.buf
1 select dbms_metadata.get_ddl( 'TABLE', 'EMP', 'SCOTT' )
2* from dual
SQL> /
DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')
--------------------------------------------------------------------------------
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"
ALTER INDEX "SCOTT"."PK_EMP" UNUSABLE 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"
CACHE
Upvotes: 3