0

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.

2
  • Elaborate a little please. Provide an example of what you are really trying to achieve. Commented Oct 26, 2012 at 14:54
  • if you use a tool like TOAD, then you can view an object (Procedure, Function, Table, Index, etc.) and say - 'see SQL script' which you can then save off somewhere. Commented Oct 26, 2012 at 14:59

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.