Published in dbms_metadata.set_transform_param, SQLTERMINATOR property

Hello

I use the dbms_metadata for the DDL for all objects in a particular schema.

DDL is recovered without any problem, but the SQLTERMINATOR is not added at the end of any DDL.

The property is used is

dmsf: = dbms_metadata.session_transform;

DBMS_METADATA.SET_TRANSFORM_PARAM (dmsf, 'SQLTERMINATOR', TRUE);

Please let me know on what I should change to solve this problem.

This is all the code that I use.

CREATE OR REPLACE TYPE ddl_ty AS OBJECT  
(  
  object_name VARCHAR2(30),  
  object_type VARCHAR2(30),  
  orig_schema VARCHAR2(30),  
  orig_ddl    CLOB  
)  
/  
CREATE OR REPLACE TYPE ddl_ty_tb AS TABLE OF ddl_ty  
/  
  
CREATE OR REPLACE FUNCTION get_object_ddl(input_values SYS_REFCURSOR)  
  RETURN ddl_ty_tb  
  PIPELINED IS  
  
  PRAGMA AUTONOMOUS_TRANSACTION;  
  
  -- variables to be passed in by sys_refcursor */  
  object_name VARCHAR2(30);  
  object_type VARCHAR2(30);  
  orig_schema VARCHAR2(30);  
  
  -- setup output record of TYPE tableddl_ty  
  out_rec ddl_ty := ddl_ty(NULL, NULL, NULL, NULL);  
  
  /* setup handles to be used for setup and fetching metadata information handles are used  
  to keep track of the different objects (DDL) we will be referencing in the PL/SQL code */  
  hopenorig   NUMBER;  
  hmodifyorig NUMBER;  
  htransddl   NUMBER;  
  dmsf        PLS_INTEGER;  
  
  /*  
  CLOBs to hold DDL  
  */  
  orig_ddl CLOB;  
BEGIN  
  /* Strip off Attributes not concerned with in DDL. If you are concerned with  
  TABLESPACE, STORAGE, or SEGMENT information just comment out these few lines. */  
  dmsf := dbms_metadata.session_transform;  
  dbms_metadata.set_transform_param(dmsf, 'SQLTERMINATOR', TRUE);  
  dbms_metadata.set_transform_param(dmsf, 'TABLESPACE', FALSE);  
  dbms_metadata.set_transform_param(dmsf, 'PRETTY', TRUE);  
  dbms_metadata.set_transform_param(dmsf, 'STORAGE', FALSE);  
-- dbms_metadata.set_transform_param(dmsf, 'SEGMENT_ATTRIBUTES', FALSE);  
  
  -- Loop through each of the rows passed in by the reference cursor  
  LOOP  
    /* Fetch the input cursor into PL/SQL variables */  
    FETCH input_values  
      INTO object_name, orig_schema, object_type;  
    EXIT WHEN input_values%NOTFOUND;  
  
    hopenorig := dbms_metadata.open(object_type);  
    dbms_metadata.set_filter(hopenorig, 'NAME', object_name);  
    dbms_metadata.set_filter(hopenorig, 'SCHEMA', orig_schema);  
  
    /* Modify the transformation to remove "orig_schema" reference*/  
    hmodifyorig := dbms_metadata.add_transform(hopenorig, 'MODIFY');  
    dbms_metadata.set_remap_param(hmodifyorig,  
                                  'REMAP_SCHEMA',  
                                  orig_schema,  
                                  NULL);  
    -- This states to created DDL instead of XML to be compared  
    htransddl := dbms_metadata.add_transform(hopenorig, 'DDL');  
  
    -- Get the DDD and store into the CLOB PL/SQL variables  
    orig_ddl := dbms_metadata.fetch_clob(hopenorig);  
  
    out_rec.object_name := object_name;  
    out_rec.object_type := object_type;  
    out_rec.orig_schema := orig_schema;  
    out_rec.orig_ddl    := orig_ddl;  
    PIPE ROW(out_rec);  
  
    -- Cleanup and release the handles  
    dbms_metadata.close(hopenorig);  
  
  END LOOP;  
  RETURN;  
END get_object_ddl;  
  
/  
  
SELECT *  
  FROM TABLE(get_object_ddl(CURSOR (SELECT object_name, owner, object_type  
                               FROM dba_objects  
                              WHERE owner = 'ALERTSASIA'  
                                    AND object_type IN  
                                    ('PACKAGE'))));  

Hello

I think that dbms_metadata.session_transform is for GET_DDL, GET_DEPENDENT_DDL and GET_GRANTED_DDL functions.

You must use set_transform_param on the htransddl handle. Add after line 65:

      dbms_metadata.set_transform_param (htransddl, 'PRETTY', true);
      dbms_metadata.set_transform_param (htransddl, 'SQLTERMINATOR', true);

Other attributes transform as TABLESPACE and STORAGE should also be applied to htransddl to remove the 40-45 lines.

You must also add a logic when you define this transform settings such as STORAGE and TABLESPACE for example cannot be applied to the PACKAGE object type.

Kind regards

Mitja

Tags: Database

Similar Questions

  • [3.2.09] output truncated dbms_metadata

    Hello

    Sorry for my bad English.

    Today I tried to use the dbms_metata package extract the list of privileges of the object for a user

    As usual, I run the following command in sql develop:

    long value 1000000000
    exec dbms_metadata.set_transform_param (dbms_metadata. SESSION_TRANSFORM 'SQLTERMINATOR', TRUE);
    Select dbms_metadata.get_granted_ddl ('OBJECT_GRANT', 'USER_TITI') of double;

    but when I click on 'run script', the result is truncated.
    I have the first line 60, with the latter truncated (missing comma)
    (I check with sqlplus, with the same exact command, I have correctly to have 186 lines).

    Another user has the same problem?

    Published by: 955770 on August 29, 2012 07:03

    >
    Today I tried to use the dbms_metata package extract the list of privileges of the object for a user
    >
    The result is of type CLOB data and there is a limit to how many characters that appear. You experience the same problem that others have when returning from CLOB data.

    See this other recent thread for possible solutions
    Re: Output of script CLOB is truncated

  • Parameter DBMS_METADATA. GET_DDL out of materialized views

    Hi all.
    My version of Oracle's 10g.

    I am extracting DDL for all database objects using the DBMS_METADATA package. I use SET_TRANSFORM_PARAM to configure the output because I need a sql code simple, without information about the attributes of storage spaces, storage and segment. Everything works well except when I work with mviews object types. I can't remove the information about the attributes of the tablespace, storage or segment for materialized views.

    I would like to know if there is a problem related to this topic. Or there is something missing in my code?

    I tried to specify the type of object such as another parameter on DBMS_METADATA. SET_TRANSFORM_PARAM but not work too.
    The only parameter transform that works very well with materialized views is the SQLTERMINATOR.

    ------
    See how I did:

    declare
    CLOB vDDL;
    Start
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA. SESSION_TRANSFORM 'STORAGE', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA. SESSION_TRANSFORM, 'TABLESPACE', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA. SESSION_TRANSFORM, "SEGMENT_ATTRIBUTES", FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA. SESSION_TRANSFORM 'SQLTERMINATOR', TRUE);

    Select dbms_metadata.get_ddl ('MATERIALIZED_VIEW', 'MV_STO020', 'HIS117_CHECK') in vDDL FROM DUAL;
    dbms_output.put_line (vDDL);
    end;
    -------
    and how the output is:

    CREATE A MATERIALIZED VIEW 'HIS117_CHECK '. "" MV_STO020 ".
    PCTFREE 10 BUNCH OF ORGANIZATION PCTUSED 40 INITRANS MAXTRANS 255 NOCOMPRESS LOGGING 1
    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
    TABLESPACE "TS_HIS117".
    IMMEDIATE CONSTRUCTION
    USING INDEX
    REFRESH THE STRENGTH TO DEMAND
    WITH A KEY PRIMARY WITH THE HELP OF DEFAULT LOCAL ROLLBACK SEGMENT
    DISABLE THE QUERY REWRITING
    IN SELECT
    STO020_MOVEMENT_LOG_ID STO020_MOVEMENT_LOG_ID
    STO020_QUANTITY STO020_QUANTITY
    STO020_DATE STO020_DATE
    STO020_BEFORE_BALANCE STO020_BEFORE_BALANCE
    STO011_PRODUCT_MOVEMENT_ID STO011_PRODUCT_MOVEMENT_ID
    ADM082_PRODUCT_ID ADM082_PRODUCT_ID
    ADM089_PRODUCT_PRESENTATION_ID ADM089_PRODUCT_PRESENTATION_ID
    STO010_MOVEMENT_TYPE_ID STO010_MOVEMENT_TYPE_ID
    STO001_STOCK_ID STO001_STOCK_ID
    STO001_TARGET_STOCK_ID STO001_TARGET_STOCK_ID
    STO003_PRODUCT_LOT_ID STO003_PRODUCT_LOT_ID
    SYS010_USER_ID SYS010_USER_ID
    EIR001_MPI EIR001_MPI
    ADM056_MEDICAL_ATTENTION_ID ADM056_MEDICAL_ATTENTION_ID
    ADM094_USE_UNIT_ID ADM094_USE_UNIT_ID
    Of
    STO020_MOVEMENT_LOG;

    Thank you in advance!

    Published by: lucporto on 08/28/2012 07:26

    The LONG data type conversion is explained on http://asktom.oracle.com if you use the search feature.
    I could not find real pointers to your original question it.

  • Not able to add "/" with dbms_metadata.

    Hi all

    I use 11 GR 2 and need to generate the ddl for grants of objects. I stopped to do it, I'm using dbms_metadata to generate it. I need to add ' / ' after each command, but it is only adding to the last page of the grants. also, even the linsize was set to 200, but the output is always wraps around before 200.
    SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT', USERNAME) || '/' DDL
    FROM DBA_USERS where username in (select grantee from dba_tab_privs) and username in ('user')
    
      GRANT SELECT ON "PACKAGING"."ASSOCIATED_COMPONENTS
    _V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."ASSOCIATED_COMPONENTS2_V" TO
    "AALKHALI"
      GRANT SELECT ON "PACKAGING"."ASSOCIATED_COMPONENTS3_V" TO "AALKHA
    LI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_REPORT1_ALL_LOC_V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_REPORT1_BYL
    OC_V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_MANIFEST_V" TO "A
    ALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_MANIFEST2_V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_COMP_STDS_V"
     TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_STDDEFAULT_V" TO "AALK
    HALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_STD_DISTCODE_V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_STD_LOCATION
    _V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_STD_LIB_V" TO "AALK
    HALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_STDSLIST_V" TO "AALKHALI"
      GRANT SELECT ON "PACKAGING"."STANDARDS_STDSLBLS_V" TO "
    AALKHALI"
    Published by: user11983993 on July 3, 2012 08:10

    Hello

    You must use dbms_metadata.set_transform_param to specify the SQLTERMINATOR (either; or /) before issuing the GET_DDL:

    System@my11g SQL>exec dbms_metadata.set_transform_param(dbms_metadata.SESSION_TRANSFORM,'SQLTERMINATOR',true);
    
    PL/SQL procedure successfully completed.
    
    System@my11g SQL>SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT', USERNAME) u_ddl
      2  FROM DBA_USERS where username in (select grantee from dba_tab_privs) and username in ('SCOTT');
    
    U_DDL
    ------------------------------------------------------------------------------------------------------------------------
    
      GRANT EXECUTE ON "SYS"."DBMS_SESSION" TO "SCOTT";
    
      GRANT EXECUTE ON "SYS"."DBMS_LOCK" TO "SCOTT";
    
      GRANT EXECUTE ON "SYS"."DBMS_ERRLOG" TO "SCOTT";
    
      GRANT EXECUTE ON "SYS"."DBMS_CRYPTO" TO "SCOTT";
    
      GRANT READ, WRITE ON DIRECTORY "FOLDER1" TO "SCOTT";
    
      GRANT READ, WRITE ON DIRECTORY "FOLDER2" TO "SCOTT";
    
      GRANT READ, WRITE ON DIRECTORY "FOLDER3" TO "SCOTT";
    
      GRANT EXECUTE ON "SYS"."TRACEME" TO "SCOTT";
    
      GRANT EXECUTE ON "SYS"."TRACEMEOFF" TO "SCOTT";
    
      GRANT EXECUTE ON "SYS"."REMOVE_FLARCH" TO "SCOTT";
    
      GRANT EXECUTE ON "SYSTEM"."REMOVE_FLARCH" TO "SCOTT";
    
      GRANT READ, WRITE ON DIRECTORY "SCOTTDIR" TO "SCOTT";
    
  • dbms_metadata for 381 triggers

    I try to extract 381 triggers in a file that I can then run to re-create triggers later.
    But when I run the result of the file I receive by underneath, they compile the triggers.
    The script below does not place a "/" at the end of eacj SQl statement.
    She does at the end of the DDL...
    END zedw_trg_adr6;
    ALTER TRIGGER 'SAPSR3 '. "' ZEDW_TRG_ADR6 ' ACTIVATE
    Instead of...
    END zedw_trg_adr6;
    /
    ALTER TRIGGER 'SAPSR3 '. "' ZEDW_TRG_ADR6 ' ACTIVATE
    /


    How can I fix the commands below?




    I use this to the DDL trigger creat ethe file to run later.
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    sqlplus "/ as sysdba".

    SET LONGCHUNKSIZE 1024
    LONG VALUE 128000
    SET ECHO OFF
    SET THE POSITION
    SET LINESIZE 512
    SET TRIMOUT ON
    SET TRIMSPOOL ON
    PACKAGING OF THE SET


    coil c:\temp\triggers_extract.sql

    Select dbms_metadata. GET_DDL (u.object_type, u.object_name, 'SAPSR3')
    u dba_objects
    where type_objet = 'TRIGGER '.
    and the owner = "SAPSR3";

    spool off;

    output

    VI triggers_extract.sql
    -Remove items ' SQL > ' lines from the top & bottom of the script.
    : wq!

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Hi Bill,

    Try to play a bit with this:

    dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
    

    Edit:
    In addition, you will need to either put all your SQL * more commands in a script, then run it only after the connection.
    Alternatively, leave termout.

    Both should remove the need to change it later.

    Concerning
    Peter

    Published by: Peter on December 6, 2011 15:13

  • Strange behavior with DBMS_METADATA while Retriving Table DDL

    Hi again, I works the DBMS_METADATA package to retrieve the table DDL to a given schema. The problem I encounter is that I am only able to get a type of table DDL at a time and I'd like to be able to recover all types of tables. When I say type table I'm talking about traditional, ITO and partitioned, although I don't know that it applies to other types of.

    My system is running 11.2.0.3 on Redhat 6 x 64 with all current patches.

    Here's my setup. I created two tables for each type.

    create table table_normal1(
        column1 varchar2(30 char),
        column2 varchar2(30 char)    
        );
        
    create table table_normal2(
        column1 varchar2(30 char),
        column2 varchar2(30 char)    
        );    
    
    create table table_index_organized1(
        column1 varchar2(30 char),
        column2 varchar2(30 char),
        constraint pk_table_index_organized1 primary key (column1)
        )
        organization index;
    
    create table table_index_organized2(
        column1 varchar2(30 char),
        column2 varchar2(30 char),
        constraint pk_table_index_organized2 primary key (column1)
        )
        organization index;    
    
    create table table_partioned1(
        column1 varchar2(30 char),
        column2 varchar2(30 char)
        )
        partition by list(column1)(
            partition p1 values ('P1'),
            partition p2 values ('P2'),
            partition p3 values ('P3')
            );
            
    create table table_partioned2(
        column1 varchar2(30 char),
        column2 varchar2(30 char)
        )
        partition by list(column1)(
            partition p1 values ('P1'),
            partition p2 values ('P2'),
            partition p3 values ('P3')
            );
    

    And here is the anonymous block, that I am running.

    declare
        v_ddl_list sys.ku$_ddls;
        v_handle number;
        v_transform_handle number;
    begin
        v_handle := dbms_metadata.open(
            object_type => 'TABLE'
            );
        dbms_metadata.set_filter(
            handle => v_handle,
            name => 'SCHEMA',
            value => USER
            );
        v_transform_handle := dbms_metadata.add_transform (
            handle => v_handle,
            name => 'DDL'
            );
        dbms_metadata.set_transform_param(
            transform_handle => v_transform_handle,
            name => 'SQLTERMINATOR',
            value => true
            );
        dbms_metadata.set_transform_param(
            transform_handle => v_transform_handle,
            name => 'PRETTY',
            value => true
            );
        dbms_metadata.set_transform_param(
            transform_handle => v_transform_handle,
            name => 'SEGMENT_ATTRIBUTES',
            value => false
            );
        dbms_metadata.set_transform_param(
            transform_handle => v_transform_handle,
            name => 'REF_CONSTRAINTS',
            value => false
            );
        dbms_metadata.set_transform_param(
            transform_handle => v_transform_handle,
            name => 'CONSTRAINTS_AS_ALTER',
            value => true
            );
        dbms_metadata.set_count(
            handle => v_handle,
            value => 1000
            );    
        v_ddl_list := dbms_metadata.fetch_ddl(
            handle => v_handle
            );  
        open :p_output for select * from table(v_ddl_list) order by to_char(substr(ddltext,1,100));                
    end;
    /
    

    If I add a Filter Expression by name, I am able to find the other tables very well but I can't get the DDL for several types.

    dbms_metadata.set_filter(
        handle => v_handle,
        name => 'NAME_EXPR',
        value => 'IN (''TABLE_NORMAL1'',''TABLE_NORMAL2'')'
        );
    

    Is this a bug or just a limitation without papers? I looked at the documentation several times and I can't find anything that mentioned this problem.

    Thank you

    I just wanted to know for all I knew it was. You have call dbms_metadata.fetch_ddl repeatedly until it returns a null value. On our production systems, this returns the DDL for tables of 200 or more in 10 seconds. I missed this little note when I was reading the documentation in the "http://docs.oracle.com/cd/E11882_01/server.112/e22490/metadata_api.htm#SUTIL1626".

    Thank you

  • DBMS_METADATA. GET_DDL does not return the entire procedure. His truncated

    SET echo off; set pagesize 0; SET long 500000; spool GenerateProcedure_Creation.sql begin dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true); dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', false); end; SELECT DBMS_METADATA.GET_DDL(u.object_type,u.object_name,u.owner) DDL from dba_objects u where u.OBJECT_TYPE = 'PROCEDURE' and owner in ('ADMIN'); spool off; 

    This returns some of the procedures as truncated.

    RUN THE FOLLOWING before RUNNING YOUR STATEMENT in sqlplus:

    long value 1000000

    then try

  • using dbms_metadata for the ddl to create directories

    Hello
    I'm working on creating a test database, which is a copy of production for 11g upgrade test. I want to get all my production database DDL to create all the directories in the new test database. I tried using dbms_metadata for it-
    Here is the code I tried to use. However, when I query the my_metadata table, nothing in there. Can someone help me with this please?

    DROP TABLE my_metadata;
    CREATE TABLE my_metadata (md CLOB);

    CREATE OR REPLACE PROCEDURE progp1_directories_extract
    AS
    hndl NUMBER; -dbms_metadata handle
    e NUMBER; -transform handle
    CLOB DDL; -Individual CLOB from the database
    BEGIN
    hndl: = DBMS_METADATA. OPEN ("DATABASE_EXPORT"); -Open the metadata
    DBMS_METADATA.set_Filter (hndl, 'INCLUDE_PATH_EXPR', ' = "DIRECTORY" "); -Filter the data according to the case
    th: = DBMS_METADATA.add_transform (hndl, 'DDL'); -Get the Handle of the transformation
    DBMS_METADATA.SET_TRANSFORM_PARAM (th, 'SQLTERMINATOR', TRUE); -Include the semicolon

    LOOP
    DDL: = DBMS_METADATA.fetch_clob (hndl); -Loop through the result set, inserting in our temporary table
    DDL OUTPUT IS NULL;

    INSERT INTO my_metadata
    (md)
    VALUES (DDL);
    COMMIT;
    END LOOP;
    DBMS_METADATA. CLOSE (hndl);
    EXCEPTION
    WHILE OTHERS
    THEN
    NULL;
    END;
    /
    display errors

    Hello

    You can get the DDL for the directory running sql in the source database.

    Select 'create directory' | OWNER: '. ' || DIRECTORY_NAME |' like ' | " ' || DIRECTORY_PATH | " ' || ';' in dba_directories;

    Concerning

  • get the table script using dbms_metadata.get_ddl but with clob field

    Thus, Oracle 11g R2...
    I use dbms_metadata.get_ddl for table scripts and it works fine...

    now, I have a table with clob field, and it does not work... I got an error "missing a closing parenthesis (ora-0907) '...
    I could paste a script I had, but I don't think that it makes no sense...

    does anyone have an experience on the use of this package on clob tables?


    TNX

    See this code.

    DECLARE
      myddl clob;
      PROCEDURE print_clob(p_clob in clob) as
        l_offset number default 1;
      BEGIN
        loop
          exit when l_offset > dbms_lob.getlength(p_clob);
          dbms_output.put_line(dbms_lob.substr(p_clob, 255, l_offset));
          l_offset := l_offset + 255;
        end loop;
      END print_clob;
      FUNCTION get_metadata return clob is
        h   number;
        th  number;
        doc clob;
      BEGIN
        h := dbms_metadata.open('TABLE');
        dbms_metadata.set_filter(h, 'SCHEMA', 'HR');
        dbms_metadata.set_filter(h, 'NAME', 'EMPLOYEES');
        th := dbms_metadata.add_transform(h, 'MODIFY');
        th := dbms_metadata.add_transform(h, 'DDL');
        --dbms_metadata.set_transform_param(th,'SEGMENT_ATTRIBUTES',false);
        doc := dbms_metadata.fetch_clob(h);
        dbms_metadata.CLOSE(h);
        return doc;
      END get_metadata;
    BEGIN
      myddl := get_metadata;
      print_clob(myddl);
    END;
    

    This procedure of print_ddl I took of the documentation.
    Use of the long VALUE. See, in the first example out put is truncated.

    SQL> SELECT dbms_metadata.get_ddl('TABLE','EMP','SCOTT') FROM dual;
    
    DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')
    --------------------------------------------------------------------------------
    
      CREATE TABLE "SCOTT"."EMP"
       (    "EMPNO" NUMBER(4,0),
            "ENAME" VARCHAR2(10),
    
    SQL> set long 10000
    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")
    
    DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')
    --------------------------------------------------------------------------------
      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 "USERS"  ENABLE,
             CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
              REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
       ) 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)
      TABLESPACE "USERS"
    
    SQL> SET LINESIZE 132
    SQL> SET pagesize 0
    SQL> SET LONG 1000000
    SQL> /
    
      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)
      TABLESPACE "USERS"  ENABLE,
             CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
              REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
       ) 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)
      TABLESPACE "USERS"
    
    SQL>
    
  • DBMS_METADATA. Need help GET_DDL

    Hello

    I use ORACLE 10 G,

    the result of this query
    SELECT DBMS_METADATA. GET_DDL ('TABLE', 'PMSSECURITY2') FROM DUAL

    Returned in the output below

    CREATE TABLE "ASSETS". "" PMSSECURITY2 ".
    ("COMP_CODE" NUMBER (4,0) ACTIVATE NOT NULL,)
    ACTIVATE THE 'BRANCH' NUMBER (4,0) NOT NULL,
    "CODE1" NUMBER (8.0) NOT NULL ACTIVATE.
    'CODE2' SELECT NOT NULL NUMBER (8.0)
    ......
    KEY ELEMENTARY SCHOOL ('COMP_CODE', 'BRANCH', "CODE1", 'CODE2')
    FOREIGN KEY ('COMP_CODE', 'QUALITY')
    REFERENCES "ASSETS". "" TURN ON THE PMSQUALITY ' ('COMP_CODE', 'CODE'),
    FOREIGN KEY ('COMP_CODE', 'BRANCH', "CODE1", 'CODE2')
    REFERENCES "ASSETS". "" ENABLE PMSSECURITY "('COMP_CODE', 'BRANCH',"CODE1", 'CODE2')
    )

    is it possible to have the same result without FOREIGN KEY references

    Knowing that I used the following to get rid of PCTFREE and storage...


    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA.session_transform, 'STORAGE', false);
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA.session_transform, 'TABLESPACE', false);
    DBMS_METADATA.SET_TRANSFORM_PARAM (dbms_metadata.session_transform, 'SEGMENT_ATTRIBUTES', false);

    Add these institutions

       dbms_metadata.set_transform_param(dbms_metadata.session_transform,'REF_CONSTRAINTS', false);
       dbms_metadata.set_transform_param(dbms_metadata.session_transform,'CONSTRAINTS', false);
    

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14258/d_metada.htm#ARPLS640

  • Need to remove the name clause and the storage of schema DDL script.

    Try to remove the clause name and storage schema of the DDL script.


    Example:

    "
    CREATE TABLE 'CPDFP '. "" PS_PT_LN_TA_SRVC_BRANCH_DTLS ".
    (ACTIVATE THE "SL_NO" NUMBER NOT NULL,)
    ACTIVATE THE "SESSION_ID" NUMBER NOT NULL,
    ACTIVATE THE "COMPANY_CODE" VARCHAR2 (15) NOT NULL,
    ACTIVATE THE "SRVC_BRANCH_CODE" VARCHAR2 (6) NOT NULL,
    ENABLE 'DEALER_CODE' VARCHAR2 (15) NOT NULL
    ) CREATION OF IMMEDIATE SEGMENT
    PCTFREE, PCTUSED, INITRANS 40 10 1 MAXTRANS 255
    REGISTRATION OF NOCOMPRESS
    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    USER_TABLES FLASH_CACHE, CELL_FLASH_CACHE DEFAULT DEFAULT)
    "TABLESPACE"CPDFP"


    On top of the query, I have to delete the name and storage schema clause...


    Can anyone suggest pls as how to do it...

    I used script below to get the ddl of the tables and I have to remove the schema name and terms of storage so pls help...

    SELECT DBMS_METADATA. GET_DDL ('TABLE', u.table_name)
    FROM USER_TABLES;


    Rgds,
    Nitesh.
    DROP TABLE t;
    create table t as select * from all_objects where 1=0;
    
    begin
    dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SEGMENT_ATTRIBUTES', false );
    dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', TRUE );
    end;
    /
    
    SELECT REPLACE(
      DBMS_METADATA.GET_DDL( 'TABLE', 'T'),
      '"'||USER||'".',
      ''
    )
    from dual;
    
     CREATE TABLE "T"
       (     "OWNER" VARCHAR2(30) NOT NULL ENABLE,
         "OBJECT_NAME" VARCHAR2(30) NOT NULL ENABLE,
         "SUBOBJECT_NAME" VARCHAR2(30),
         "OBJECT_ID" NUMBER NOT NULL ENABLE,
         "DATA_OBJECT_ID" NUMBER,
         "OBJECT_TYPE" VARCHAR2(19),
         "CREATED" DATE NOT NULL ENABLE,
         "LAST_DDL_TIME" DATE NOT NULL ENABLE,
         "TIMESTAMP" VARCHAR2(19),
         "STATUS" VARCHAR2(7),
         "TEMPORARY" VARCHAR2(1),
         "GENERATED" VARCHAR2(1),
         "SECONDARY" VARCHAR2(1),
         "NAMESPACE" NUMBER NOT NULL ENABLE,
         "EDITION_NAME" VARCHAR2(30)
       ) ;
    

    For instructions CREATE TABLE for all the tables in your schema:

    begin
    dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SEGMENT_ATTRIBUTES', false );
    dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', TRUE );
    end;
    /
    SELECT REPLACE(
      EXTRACTVALUE(
        XMLTYPE(
          DBMS_XMLGEN.GETXML(
            'SELECT DBMS_METADATA.GET_DDL( ''TABLE'', '''||TABLE_NAME||''' ) SCR FROM DUAL'
          )
        )
        , '/ROWSET/ROW/SCR'
      ),
      '"'||USER||'".',
      ''
    )
    OBJECT_SCRIPT
    FROM USER_TABLES;
    

    I post out ;)

    Published by: Ashton stew on March 7, 2013 11:47

  • Creation of primary keys, foreign keys and indexes

    Hello

    I created 60 new tables based on 60 existing tables.

    The 60 current tables are named FY11_ACC1, FY11_ACC2, FY11_SALES1, FY11_SALES2..., but all of the 60 tables start with FY11. I created the same structured tables but with names like FY12_ACC1, FY12_ACC2, FY12_SALES1, FY12_SALES2 FY12...

    I used the below SQL and generated SQL code.

    Select 'create table ' | Replace (table_name, 11, 12).
    ' in select * from '. table_name | "where 1 = 0'.
    from user_tables;

    But this did not generate the PRIMARY KEYS, FOREIGN KEYS and INDEXES. How can I automatically or with similar like SQL above? _

    Thanks for your time and your help.







    How can I create primary keys, foreign keys and indexes for all

    ssk1974 wrote:
    Can you please provide me with more information or examples.

    Something like:

    SET SERVEROUTPUT ON FORMAT WORD
    DECLARE
        h   NUMBER;
        th  NUMBER;
        ddl CLOB;
    BEGIN
        h := DBMS_METADATA.OPEN('TABLE_EXPORT');
        DBMS_METADATA.SET_FILTER(h,'SCHEMA','SCOTT');
        DBMS_METADATA.SET_FILTER(h,'NAME','DEPT');
        DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''TABLE_DATA''');
        DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''STATISTICS''');
        th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL');
        DBMS_METADATA.SET_TRANSFORM_PARAM(th,'PRETTY',false);
        DBMS_METADATA.SET_TRANSFORM_PARAM(th,'SQLTERMINATOR',true);
        LOOP
          ddl := DBMS_METADATA.FETCH_CLOB(h);
          EXIT WHEN DDL IS NULL;
          DBMS_OUTPUT.PUT_LINE (ddl);
        END LOOP;
        DBMS_METADATA.CLOSE(h);
    END;
    /
    
      CREATE TABLE "SCOTT"."DEPT" ("DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14),
    "LOC" VARCHAR2(13),  CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") 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" ;
    
      CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO") 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" ;
    
      ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO")
    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;
    
    PL/SQL procedure successfully completed.
    
    SQL>  
    

    SY.

    Published by: Solomon Yakobson January 5, 2012 16:22

  • Moving all the newspapers and Materialized View at the schema level using the data pump in

    Hi Experts,

    Please help me on how I can exp/imp all materialized views andMV logs (as are some MVs) only the full scheme of other databases. I want to exclude everything else.

    Concerning
    -Samar-

    Using DBMS_METADATA. Create the following SQL script:

    SET FEEDBACK OFF
    SET SERVEROUTPUT ON FORMAT WORD_WRAPPED
    SET TERMOUT OFF
    SPOOL C:\TEMP\MVIEW.SQL
    DECLARE
        CURSOR V_MLOG_CUR
          IS
            SELECT  DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW_LOG',LOG_TABLE) DDL
              FROM  USER_MVIEW_LOGS;
        CURSOR V_MVIEW_CUR
          IS
            SELECT  DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW',MVIEW_NAME) DDL
              FROM  USER_MVIEWS;
    BEGIN
        DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
        FOR V_REC IN V_MLOG_CUR LOOP
          DBMS_OUTPUT.PUT_LINE(V_REC.DDL);
        END LOOP;
        FOR V_REC IN V_MVIEW_CUR LOOP
          DBMS_OUTPUT.PUT_LINE(V_REC.DDL);
        END LOOP;
    END;
    /
    SPOOL OFF
    

    In my case the script is saved as C:\TEMP\MVIEW_GEN. SQL. Now I will create a journal mview and mview in schema SCOTT and run the script above:

    SQL> CREATE MATERIALIZED VIEW LOG ON EMP
      2  /
    
    Materialized view log created.
    
    SQL> CREATE MATERIALIZED VIEW EMP_MV
      2  AS SELECT * FROM EMP
      3  /
    
    Materialized view created.
    
    SQL> @C:\TEMP\MVIEW_GEN
    SQL> 
    

    Run the C:\TEMP\MVIEW_GEN script. SQL generated a C:\TEMP\MVIEW queue. SQL:

      CREATE MATERIALIZED VIEW LOG ON "SCOTT"."EMP"
     PCTFREE 10 PCTUSED 30 INITRANS
    1 MAXTRANS 255 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" 
    
    WITH PRIMARY KEY EXCLUDING NEW VALUES;
    
      CREATE MATERIALIZED VIEW "SCOTT"."EMP_MV" ("EMPNO", "ENAME", "JOB", "MGR",
    "HIREDATE", "SAL", "COMM", "DEPTNO")
      ORGANIZATION HEAP 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"
      BUILD IMMEDIATE
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
    
    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"
      REFRESH FORCE ON
    DEMAND
      WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
      USING ENFORCED
    CONSTRAINTS DISABLE QUERY REWRITE
      AS SELECT "EMP"."EMPNO"
    "EMPNO","EMP"."ENAME" "ENAME","EMP"."JOB" "JOB","EMP"."MGR"
    "MGR","EMP"."HIREDATE" "HIREDATE","EMP"."SAL" "SAL","EMP"."COMM"
    "COMM","EMP"."DEPTNO" "DEPTNO" FROM "EMP" "EMP";
                                   
    

    Now, you can run this on the database. You may need to adjust the tablespace and storage clauses. Or you can add more DBMS_METADATA. SET_TRANSFORM_PARAM calls to C:\TEMP\MVIEW_GEN. SQL to force DBMS_METADATA not to include the tablespace or / and the terms of storage.

    SY.

  • lack of ';' the DDL

    Hi all
    I'm running under query to get the ddl for a table using the dbms_metadata package.
    query:

    SELECT dbms_metadata.get_ddl (replace (OBJECT_TYPE, ' ', '_'), OBJECT_NAME, OWNER)
    FROM DBA_OBJECTS
    WHERE OBJECT_TYPE in ('SEQUENCE',
    'PROCEDURE ',.
    "DATABASE LINK",
    'PACKAGE ',.
    'PACKAGE BODY ',.
    "MATERIALIZED VIEW.
    "TABLE."
    "INDEX."
    "DISPLAY."
    'FUNCTION')
    AND OWNER = 'AI_ADM. '
    AND OBJECT_NAME LIKE 'TEST_EXPORT_DDL ';

    Returns the DOF properly but lack of ';' at the end, but when I run the same query on sql developer I get ';' at the end why?

    Any suggestions would be helpful,
    Thank you
    J

    Question:

    BEGIN
        dbms_metadata.set_transform_param(
                                          dbms_metadata.session_transform,
                                          'SQLTERMINATOR',
                                          TRUE
                                         );
    END;
    /
    

    before you run your SELECTION.

    SY.

  • Get ORA-00001, but couldn't find the constraint

    Hi all

    Here's the scenario that I am facing: I have a table which has no constraints, but when trying to insert data into this table, I get some PRA-00001. When I search this constraint, I couldn't find it.
    SQL> set long 9999999
    SQL> execute dbms_metadata.set_transform_param(dbms_metadata.session_transform,'SEGMENT_ATTRIBUTES', false);
    
    PL/SQL procedure successfully completed.
    
    SQL> execute dbms_metadata.set_transform_param(dbms_metadata.session_transform,'SQLTERMINATOR', TRUE);
    
    PL/SQL procedure successfully completed.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select dbms_metadata.get_ddl('TABLE','CRT_CONTRACTOR_PARTNERS_BK',user) DDL
      2* from dual
    SQL> /
    
      CREATE TABLE "PROJ"."CRT_CONTRACTOR_PARTNERS_BK"
       (     "CRR_YEAR" NUMBER(4,0) DEFAULT NULL,
         "CRR_NO" NUMBER(6,0),
         "NO" NUMBER(6,0),
         "NAME" VARCHAR2(60),
         "OTE_CODE" VARCHAR2(5),
         "PARTNERSHIP_PERC" NUMBER(5,2),
         "CNT_CODE" VARCHAR2(5),
         "PASSPORT_NO" VARCHAR2(15),
         "FILTERED_NAME" VARCHAR2(60),
         "APP_ID" NUMBER
       ) ;
    
    
    
    SQL> show user
    USER is "PROJ"
    SQL> insert into "PROJ"."CRT_CONTRACTOR_PARTNERS_BK" select * from "PROJ"."CRT_CONTRACTOR_PARTNERS_BK";
    insert into "PROJ"."CRT_CONTRACTOR_PARTNERS_BK" select * from "PROJ"."CRT_CONTRACTOR_PARTNERS_BK"
    *
    ERROR at line 1:
    ORA-00001: unique constraint (PROJ.PARTS_PK) violated
    
    
    SQL> SELECT constraint_name FROM all_constraints WHERE table_name='CRT_CONTRACTOR_PARTNERS_BK';
    
    no rows selected
    
    SQL> ed
    Wrote file afiedt.buf
    
      1* SELECT constraint_name FROM all_constraints WHERE constraint_name='PARTS_PK'
    SQL> /
    
    no rows selected
    
    SQL> select * from v$version;
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Can you help me solve this mystery?

    Kind regards

    Riaz

    Hello

    You can also post the output below.

    select index_name from all_indexes where table_name = 'CRT_CONTRACTOR_PARTNERS_BK'
    

    Assumption, that you are connected to aid user proj.

    Concerning
    Anurag

Maybe you are looking for