DBMS_METADATA.GET_DDL - output trucating

Hi,
I am generating Database Package Scripts using the following.
=====================================================
set pagesize 0
set long 90000
set feedback off;
column DDL format a80 WORD_WRAPPED
spool FMONTUSER_PACKAGE.sql
select dbms_metadata.get_ddl(object_type,object_name,owner) DDL from dba_objects
where owner='FMONTUSER' and
object_type in('PACKAGE');
spool off;
============================================
This is the last PROCEDURE of Last PAKCGE in FMONTUSER_PACKAGE.sql
=============================================
PROCEDURE insert_loan_year_end_data(argloan_id IN LOAN.LOAN_ID%TYPE,
arg_temp_prio_end_row IN TEMP_PRIOR_YEAR_END%ROWTYPE)
IS
v_as_of_dt LOAN_YEAR_END_DATA.ASOFDATE%TYPE;
BEGIN
-- Insert the record into original loan table
DBMS_OUTPUT.put_line ('before insert LOAN_YEAR_END_DATA');
v_as_of_dt := arg_temp_prio_end_row.AS_OF_DATE;
INSERT INTO LOAN_YEAR_END_DATA     VALUES(LOAN_YEAR_END_DATA_SEQ.NEXTVAL,argloan_id,
arg_temp_
prio_end_row.BEGINNING_PRINCIPAL_BAL,arg_temp_prio_end_row.YTD_PRINCIPAL_PAID,
=============================================
I am getting trucated some lines in this procedure.
I increased 'set long 90000' to 'set long 100000'
Still I am getting truncated output.
Please help me to solve this.
regards,
Mathew

Hi,
This script I am using.
=======================================
set pagesize 0
--set long 90000
set long 2000000000
set feedback off;
column DDL format a80 WORD_WRAPPED
EXECUTE dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',true);
EXECUTE dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY',true);
EXECUTE dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',true);
EXECUTE dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',false);
EXECUTE dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS_AS_ALTER', false);
EXECUTE dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'STORAGE', false );
EXECUTE dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SEGMENT_ATTRIBUTES', false );
EXECUTE dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'TABLESPACE', false );
spool FMONTUSER_PACKAGE.sql
REM -------------------------------------------------------------------------------------------------------
REM FMONTUSER_PACKAGE.sql
REM PACKAGE.sql
select dbms_metadata.get_ddl(object_type,object_name,owner) DDL from dba_objects
where owner='FMONTUSER' and
object_type in('PACKAGE');
spool off;
regards
Mathew

Similar Messages

  • Dbms_metadata.get_ddl output format is not runable.

    Hi,
    I am using dbms_metadata.get_ddl to extract the objects. But the output returned is not runable.
    In output lines are broken so it makes unable to run that code.
    Ex. If I run this for all the synonyms like this.
    set pagesize 0
    set long 90000
    set feedback off
    set echo off
    spool /tmp/FixSyn.out
    select
    DBMS_METADATA.GET_DDL('SYNONYM',u.object_name,'ADMINSRV_D1')
    from
    dba_objects u
    where
    object_type = 'SYNONYM' and owner= 'ADMINSRV_D1';
    spool off;
    Output from this is coming like this.
    CREATE OR REPLACE SYNONYM "ADMINSRV_D1"."ASSTATEAPPORVALTYPE222" FOR "ADMINSRV
    _D1"."ASSTATEAPPORVALTYPE";
    CREATE OR REPLACE SYNONYM "ABC"."ASSTATEAPPORVALTYPE3" FOR "ADMINSRV_D
    1"."ASSTATEAPPORVALTYPE";
    This is broken in multiple lines so not possible to run this.
    Please provide any solution to fix this output.
    Thanks a lot,
    Amit.

    How about using word_wrapped
    set pagesize 0
    set long 90000
    set lines 131
    column txt format a121 word_wrapped
    set feedback off
    set echo off
    spool /tmp/FixSyn.out
    select
    DBMS_METADATA.GET_DDL('SYNONYM',u.object_name,'ADMINSRV_D1') txt
    from
    dba_objects u
    where
    object_type = 'SYNONYM' and owner= 'ADMINSRV_D1';
    spool off;
    For help on Column and default attributes.
    SQL> help column
    You can also check asktom replies.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:30802454515375
    Regards,
    Sabdar Syed.

  • Setting DBMS_METADATA.GET_DDL Output for Materialized Views

    Hi all.
    My Oracle version is 10g.
    I'm extracting the DDL of all the objects from database using the DBMS_METADATA package. I'm using SET_TRANSFORM_PARAM to configure the output because I need a simple sql code, without information about tablespaces, storage and segment attributes. Everything works fine except when I'm working with mviews object types. I can't remove the information about tablespace, storage or segment attributes for materialized views.
    I would like to know if there's a related issue about it. Or there's something missing in my code?
    I tried to specify the object type as another parameter on DBMS_METADATA.SET_TRANSFORM_PARAM but don't work too.
    The only transform parameter that works fine with Materialized Views is the SQLTERMINATOR.
    See how I have done:
    declare
    vDDL clob;
    begin
    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') into vDDL FROM DUAL;
    dbms_output.put_line (vDDL);
    end;
    and how the output is:
    CREATE MATERIALIZED VIEW "HIS117_CHECK"."MV_STO020"
    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)
    TABLESPACE "TS_HIS117"
    BUILD IMMEDIATE
    USING INDEX
    REFRESH FORCE ON DEMAND
    WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
    DISABLE QUERY REWRITE
    AS 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
    FROM
    STO020_MOVEMENT_LOG;
    Thank you in advanced!
    Edited by: lucporto on 28/08/2012 07:26

    Right. I found this way but I consider this just a quick fix, because I think there should be a better way to do this.
    create table t_clob (c_long);
    declare
    p clob;
    begin
    delete from t_clob;
    execute immediate 'insert into t_clob (select to_lob(query) from dba_mviews where owner = :1 and mview_name = :2)'
    USING 'HIS117', 'MV_STO020';
    select 'CREATE MATERIALIZED VIEW MV_STO020' || chr(10) ||
    'REFRESH ON DEMAND' || chr(10) || 'AS' || CHR(10) || mv.c_long
    into p
    from t_clob mv;
    dbms_output.put_line(p);
    end;
    Thanks all.

  • Output cut off from dbms_metadata.get_ddl

    When I execute DBMS_METADATA.GET_DDL('TABLE','table_name','schema_name'), the output for some tables is cut off. When I run it from SQL Plus or Toad, it works fine. Is there a setting that I am missing.
    Thanks

    [email protected] wrote:
    When I execute DBMS_METADATA.GET_DDL('TABLE','table_name','schema_name'), the output for some tables is cut off. When I run it from SQL Plus or Toad, it works fine. Is there a setting that I am missing.You did not tell where are you running the dbms_metadata package.
    If you can set long 10000 on the client utility try this then.
    Otherwise SQLPLUS is the best way to extract metadata and spool it to the file.
    HTH
    SS

  • DBMS_METADATA.GET_DDL- how does it format output

    I call "DBMS_METADATA.GET_DDL" to get package body source code, see example call below.
    Can i be always sure that it will always:
    1. Return schema name before package name as for example this: "MYSCHEMA"."COLLECTSTATS". Or may it return sometimes without schema/owner-name the package name as " CREATE OR REPLACE PACKAGE BODY "COLLECTSTATS" IS"
    2. Will it always be in capital letters the "owner.packagename" part?
    3. wil lthere always be Double quotes surrounding package name and owner name as "MYSCHEMA"."COLLECTSTATS"?
    select DBMS_METADATA.GET_DDL('PACKAGE_BODY','COLLECTSTATS','MYSCHEMA') from DUAL;
    Result:
    CREATE OR REPLACE PACKAGE BODY "MYSCHEMA"."COLLECTSTATS" IS
        PROCEDURE save_log(p_logrec IN LiveStatsLog%ROWTYPE) IS

    Can i be always sure that it will always:
    1. Return schema name before package name as for example this: "MYSCHEMA"."COLLECTSTATS". Or may it return sometimes without schema/owner-name the package name as " CREATE OR REPLACE PACKAGE BODY "COLLECTSTATS" IS"This is controlable through a parameter
    2. Will it always be in capital letters the "owner.packagename" part?If you have created object names with double quotes when you defined it like:
    Create package "p"then no, it will keep the case as it appears in the data dixtionary. If you never use double quotes when creating objects, then ot will always be upper case.
    3. wil lthere always be Double quotes surrounding package name and owner name as "MYSCHEMA"."COLLECTSTATS"?Yes, this is done so that case can be preserved if neccessary.
    John

  • DBMS_METADATA.GET_DDL and Materialized View

    hi gurus,
    In 10gR2, i have created a materialized view EMP_MV with a simple structure.
    I wanted to get the DDL of EMP_MV.
    I used DBMS_METADATA to get the DDL,
    select DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET') into v_return from dual;
    Output
    CREATE MATERIALIZED VIEW "TARGET"."EMP_MV"
    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)
    TABLESPACE "TARGET_TS_01"
    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)
    TABLESPACE "TARGET_TS_01"
    REFRESH FAST ON DEMAND
    WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
    DISABLE QUERY REWRITE
    AS select empid,empname,address from web.emp
    Is there any way to get only SELECT part of this MV, ie select empid,empname,address from web.emp directly from dictionary without any string manipulation?
    tia,
    newbie

    Yes you can do it. By using INSTR and SUBTR against the result of GET_DDL function
    Try this:
    select substr(DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET'),instr(DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET'),'select'),1000)
    into v_return from dual;- - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • DBMS_METADATA.GET_DDL inside the pl/sql procedure

    We have a requirement to drop certain materialized view and need to recreate based on certain condition inside the
    pl/sql procedure.i am using the dbms_metadata to get the Mv ddls.
    var1 := 'SELECT DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW,'MV_NAME','OWNER')'|| 'from dual' || ';' ;
    dbms_output.put_line(var1);
    But i am unable to get the create ddl syntax in var1.
    Can anyone help me on this

    Hi Deepu,
    you are not helping us too much. You information are coming drop by drop.
    Anyway, I don't have a materialized view but I have tried with a table.
    Here is my test and output (what I expect you too show us too):
    First test using normal SELECT FROM DUAL:
    SET LONG 2000000
    SET HEAD OFF
    SET ECHO ON
    SELECT DBMS_METADATA.get_ddl ('TABLE', 'ALERT_QT', 'SYS') FROM DUAL;
    Output:
    SQL>
    SQL> SELECT DBMS_METADATA.get_ddl ('TABLE', 'ALERT_QT', 'SYS') FROM DUAL;
      CREATE TABLE "SYS"."ALERT_QT"
       (    "Q_NAME" VARCHAR2(30),
            "MSGID" RAW(16),
            "CORRID" VARCHAR2(128),
            "PRIORITY" NUMBER,
            "STATE" NUMBER,
            "DELAY" TIMESTAMP (6),
            "EXPIRATION" NUMBER,
            "TIME_MANAGER_INFO" TIMESTAMP (6),
            "LOCAL_ORDER_NO" NUMBER,
            "CHAIN_NO" NUMBER,
            "CSCN" NUMBER,
            "DSCN" NUMBER,
            "ENQ_TIME" TIMESTAMP (6),
            "ENQ_UID" VARCHAR2(30),
            "ENQ_TID" VARCHAR2(30),
            "DEQ_TIME" TIMESTAMP (6),
            "DEQ_UID" VARCHAR2(30),
            "DEQ_TID" VARCHAR2(30),
            "RETRY_COUNT" NUMBER,
            "EXCEPTION_QSCHEMA" VARCHAR2(30),
            "EXCEPTION_QUEUE" VARCHAR2(30),
            "STEP_NO" NUMBER,
            "RECIPIENT_KEY" NUMBER,
            "DEQUEUE_MSGID" RAW(16),
            "SENDER_NAME" VARCHAR2(30),
            "SENDER_ADDRESS" VARCHAR2(1024),
            "SENDER_PROTOCOL" NUMBER,
            "USER_DATA" "SYS"."ALERT_TYPE" ,
            "USER_PROP" "SYS"."ANYDATA" ,
             PRIMARY KEY ("MSGID")
      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)
      TABLESPACE "SYSAUX"  ENABLE
       ) USAGE QUEUE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGIN
    G
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "SYSAUX"
    OPAQUE TYPE "USER_PROP" STORE AS LOB (
      ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      CACHE
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))
    {code}
    Now with the procedure storing in CLOB variable
    {code:sql}
    SET SERVEROUTPUT ON SIZE UNLIMITED
    SET LIN 5000
    SET LONG 20000000
    SET ECHO ON
    DECLARE
       l_clob         CLOB;
    BEGIN
       l_clob := DBMS_METADATA.get_ddl ('TABLE', 'ALERT_QT', 'SYS');
       DBMS_OUTPUT.put_line (l_clob);
    END;
    Output:
    SQL>
    SQL> DECLARE
      2     l_clob         CLOB;
      3  BEGIN
      4     l_clob := DBMS_METADATA.get_ddl ('TABLE', 'ALERT_QT', 'SYS');
      5     DBMS_OUTPUT.put_line (l_clob);
      6  END;
      7  /
      CREATE TABLE "SYS"."ALERT_QT"
       (    "Q_NAME" VARCHAR2(30),
            "MSGID" RAW(16),
            "CORRID" VARCHAR2(128),
            "PRIORITY" NUMBER,
            "STATE" NUMBER,
            "DELAY" TIMESTAMP (6),
            "EXPIRATION" NUMBER,
            "TIME_MANAGER_INFO" TIMESTAMP (6),
            "LOCAL_ORDER_NO" NUMBER,
            "CHAIN_NO" NUMBER,
            "CSCN" NUMBER,
            "DSCN" NUMBER,
            "ENQ_TIME" TIMESTAMP (6),
            "ENQ_UID" VARCHAR2(30),
            "ENQ_TID" VARCHAR2(30),
            "DEQ_TIME" TIMESTAMP (6),
            "DEQ_UID" VARCHAR2(30),
            "DEQ_TID" VARCHAR2(30),
            "RETRY_COUNT" NUMBER,
            "EXCEPTION_QSCHEMA" VARCHAR2(30),
            "EXCEPTION_QUEUE" VARCHAR2(30),
            "STEP_NO" NUMBER,
            "RECIPIENT_KEY" NUMBER,
            "DEQUEUE_MSGID" RAW(16),
            "SENDER_NAME" VARCHAR2(30),
            "SENDER_ADDRESS" VARCHAR2(1024),
            "SENDER_PROTOCOL" NUMBER,
            "USER_DATA" "SYS"."ALERT_TYPE" ,
            "USER_PROP" "SYS"."ANYDATA" ,
             PRIMARY KEY ("MSGID")
      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)
      TABLESPACE "SYSAUX"  ENABLE
       ) USAGE QUEUE 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 "SYSAUX"
    OPAQUE TYPE "USER_PROP" STORE AS LOB (
      ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      CACHE
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))
    {code}
    It should be nice if you could post your tests too if they are not working.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • DBMS_METADATA.GET_DDL doesn't include function parameters

    Sometimes, when I call DBMS_METADATA.GET_DDL to get the DDL statement for a function (which we always do to ensure we're starting from the source that's actually in production), the returned text doesn't include the parameters. Other times, it does, and I'm not able to see any pattern.
    I was going to just make a function and show the output, but that did show the parameters. Then I tried calling GET_DDL while logged in as SYS as SYSDBA on my development database, and I still did not get the parameters, so I don't think it's a permissions issue.
    Does anyone have any idea what's going on here?

    It's really difficult to show you exactly what I'm doing when I can't consistently reproduce the problem, as I described.
    But here, I'll try.
    declare
         the_ddl clob;
    begin
         the_ddl := dbms_metadata.get_ddl('FUNCTION', '*****', '*****');
         dbms_output.enable(null);
         dbms_output.put_line(the_ddl);
    end;
    /Sometimes, it produces output like this:
    CREATE OR REPLACE FUNCTION "*****"."*****" (
         ***** in varchar2,
         ***** in number,
    ) return *****
    ...And other times, it produces output like this:
    CREATE OR REPLACE FUNCTION "*****"."*****" return *****
    ...I am not able to determine any consistent reason for this. In our production database, I can log in as myself and get the parameters for a specific function, but another user (that our automated process uses) doesn't see the parameters. In my development database, I log in as myself and I do not see the parameters, but I still don't see them when I log in as SYS AS SYSDBA.
    For what it's worth, if I recreate the function on my development database, then subsequent calls do show the parameters.

  • DBMS_METADATA.GET_DDL help needed

    Hello,
    I am using ORACLE 10G,
    the result of this query
    SELECT DBMS_METADATA.GET_DDL('TABLE', 'PMSSECURITY2') FROM DUAL
    Returned the below output
    CREATE TABLE "ASSETS"."PMSSECURITY2"
    ( "COMP_CODE" NUMBER(4,0) NOT NULL ENABLE,
    "BRANCH" NUMBER(4,0) NOT NULL ENABLE,
    "CODE1" NUMBER(8,0) NOT NULL ENABLE,
    "CODE2" NUMBER(8,0) NOT NULL ENABLE
    PRIMARY KEY ("COMP_CODE", "BRANCH", "CODE1", "CODE2")
    FOREIGN KEY ("COMP_CODE", "QUALITY")
    REFERENCES "ASSETS"."PMSQUALITY" ("COMP_CODE", "CODE") ENABLE,
    FOREIGN KEY ("COMP_CODE", "BRANCH", "CODE1", "CODE2")
    REFERENCES "ASSETS"."PMSSECURITY" ("COMP_CODE", "BRANCH", "CODE1", "CODE2") ENABLE
    is there any way to have the same output without the FOREIGN KEY references,
    Knowing that i used the below to get rid of PCTFREE and the 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 as well
       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

  • How to suppress SCHEMA_OWNER when using DBMS_METADATA.GET_DDL

    Hi,
    I was wondering, is it possible to suppress the owner when using dbms_metadata.get_ddl?
    SQL> select * from v$version where rownum = 1
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    SQL> exec dbms_metadata.set_transform_param (dbms_metadata.session_transform,'SEGMENT_ATTRIBUTES',false)
    SQL> select dbms_metadata.get_ddl('TABLE','EMP') from dual
    DBMS_METADATA.GET_DDL('TABLE','EMP')                                           
      CREATE TABLE "SCOTT"."EMP"                                                   
       (     "EMPNO" NUMBER(4,0) NOT NULL ENABLE,                                      
         "ENAME" VARCHAR2(10),                                                         
         "JOB" VARCHAR2(9),                                                            
         "MGR" NUMBER(4,0),                                                            
         "HIREDATE" DATE,                                                              
         "SAL" NUMBER(7,2),                                                            
         "COMM" NUMBER(7,2),                                                           
         "DEPTNO" NUMBER(2,0)                                                          
       )I would like to get rid of the "SCOTT". Alternatively to change it into something else.
    Is that possible, without post processing the output, that is?
    Regards
    Peter

    Hi Karthick,
    I was afraid that would be the answer. It can be done, but it seems rather convoluted:
    SQL> create or replace function get_table_ddl(table_name    varchar2
                                            ,schema        varchar2 default user
                                            ,new_owner     varchar2 default null)
       return clob
    is
       v_handle        number;
       v_transhandle   number;
       v_ddl           clob;
    begin
       v_handle := dbms_metadata.open('TABLE');
       dbms_metadata.set_filter(v_handle, 'SCHEMA', schema);
       dbms_metadata.set_filter(v_handle, 'NAME', table_name);
       v_transhandle := dbms_metadata.add_transform(v_handle, 'MODIFY');
       dbms_metadata.set_remap_param(v_transhandle,'REMAP_SCHEMA',schema,new_owner);
       v_transhandle := dbms_metadata.add_transform(v_handle, 'DDL');
       dbms_metadata.set_transform_param(v_transhandle,'SEGMENT_ATTRIBUTES',false);
       v_ddl := dbms_metadata.fetch_clob(v_handle);
       dbms_metadata.close(v_handle);
       return v_ddl;
    end;
    Function created.
    SQL> select get_table_ddl('EMP') from dual
    GET_TABLE_DDL('EMP')                                                           
      CREATE TABLE "EMP"                                                           
       (     "EMPNO" NUMBER(4,0) NOT NULL ENABLE,                                      
         "ENAME" VARCHAR2(10),                                                         
         "JOB" VARCHAR2(9),                                                            
         "MGR" NUMBER(4,0),                                                            
         "HIREDATE" DATE,                                                              
         "SAL" NUMBER(7,2),                                                            
         "COMM" NUMBER(7,2),                                                           
         "DEPTNO" NUMBER(2,0)                                                          
    1 row selected.Regards
    Peter

  • CTAS using dbms_metadata.get_ddl for Partitioned table

    Hi,
    I would like to create a temporary table from a partitioned table using CTAS. I plan to use the following steps in a PL/SQL procedure:
    1. Use dbms_metadata.get_ddl to get the script
    2. Use raplace function to change the tablename to temptable
    3. execute the script to get the temp table created.
    SQL> create or replace procedure p1 as
    2 l_clob clob;
    3 str long;
    4 begin
    5 SELECT dbms_metadata.get_ddl('TABLE', 'FACT_TABLE','USER1') into l_clob FROM DUAL;
    6 dbms_output.put_line('CLOB Length:'||dbms_lob.getlength(l_clob));
    7 str:=dbms_lob.substr(l_clob,dbms_lob.getlength(l_clob),1);
    8 dbms_output.put_line('DDL:'||str);
    9 end;
    12 /
    Procedure created.
    SQL> exec p1;
    CLOB Length:73376
    DDL:
    PL/SQL procedure successfully completed.
    I cannot see the DDL at all. Please help.

    Thanks Adam. The following piece of code is supposed to do that. But, its failing because the dbms_lob.substr(l_clob,4000,4000*v_intIdx +1); is putting newline and therefore dbms_sql.parse
    is failing.
    Please advice.
    create table my_metadata(stmt_no number, ddl_stmt clob);
    CREATE OR REPLACE package USER1.genTempTable is
    procedure getDDL;
    procedure createTempTab;
    end;
    CREATE OR REPLACE package body USER1.genTempTable is
    procedure getDDL as
    Description: get a DDL from a partitioned table and change the table name
    Reference: Q: How Could I Format The Output From Dbms_metadata.Get_ddl Utility? [ID 394143.1]
    l_clob clob := empty_clob();
    str long;
    l_dummy varchar2(25);
    dbms_lob does not have any replace function; the following function is a trick to do that
    procedure lob_replace( p_lob in out clob, p_what in varchar2, p_with in varchar2 )as
    n number;
    begin
    n := dbms_lob.instr( p_lob, p_what );
    if ( nvl(n,0) > 0 )
    then
    dbms_lob.copy( p_lob,
    p_lob,
    dbms_lob.getlength(p_lob),
    n+length(p_with),
    n+length(p_what) );
    dbms_lob.write( p_lob, length(p_with), n, p_with );
    if ( length(p_what) > length(p_with) )
    then
    dbms_lob.trim( p_lob,
    dbms_lob.getlength(p_lob)-(length(p_what)-length(p_with)) );
    end if;
    end if;
    end lob_replace;
    begin
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES',false);
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',true);
    DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES',false);
    execute immediate 'truncate table my_metadata';
    -- Get DDL
    SELECT dbms_metadata.get_ddl('TABLE', 'FACT','USER1') into l_clob FROM DUAL;
    -- Insert the DDL into the metadata table
    insert into my_metadata values(1,l_clob);
    commit;
    -- Change the table name into a temporary table
    select ddl_stmt into l_clob from my_metadata where stmt_no =1 for update;
    lob_replace(l_clob,'"FACT"','"FACT_T"');
    insert into my_metadata values(2,l_clob);
    commit;
    -- execute immediate l_clob; <---- Cannot be executed in 10.2.0.5; supported in 11gR2
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'DEFAULT');
    end getDDL;
    Procedure to create temporary table
    procedure createTempTab as
    v_intCur pls_integer;
    v_intIdx pls_integer;
    v_intNumRows pls_integer;
    v_vcStmt dbms_sql.varchar2a;
    l_clob clob := empty_clob();
    l_str varchar2(4000);
    l_length number;
    l_loops number;
    begin
    select ddl_stmt into l_clob from my_metadata where stmt_no=2;
    l_length := dbms_lob.getlength(l_clob);
    l_loops := ceil(l_length/4000);
    for v_intIdx in 0..l_loops loop
    l_str:=dbms_lob.substr(l_clob,4000,4000*v_intIdx +1);
    l_str := replace(l_str,chr(10),'');
    l_str := replace(l_str,chr(13),'');
    l_str := replace(l_str,chr(9),'');
    v_vcStmt(v_intIdx) := l_str;
    end loop;
    for v_intIdx in 0..l_loops loop
    dbms_output.put_line(v_vcStmt(v_intIdx));
    end loop;
    v_intCur := dbms_sql.open_cursor;
    dbms_sql.parse(
    c => v_intCur,
    statement => v_vcStmt,
    lb => 0,
    --ub => v_intIdx,
    ub => l_loops,
    lfflg => true,
    language_flag => dbms_sql.native);
    v_intNumRows := dbms_sql.execute(v_intCur);
    dbms_sql.close_cursor(v_intCur);
    end createTempTab;
    end;
    /

  • Error while viewing Scripts using dbms_metadata.get_ddl

    select dbms_metadata.get_ddl('TABLE',table_name,'DWHOWN') from user_tables
    DBMS_METADATA.GET_DDL('TABLE',TABLE_NAME,'DWHOWN')
    CREATE TABLE "DWHOWN"."T_DWBN_RELATION_MASTER"
    ( "BUSINESS_DATE" DATE NOT
    CREATE TABLE "DWHOWN"."TMP_CS_CUST_UD_CODES"
    ( "BUSINESS_DATE" DATE NOT N
    ERROR:
    ORA-31603: object "BIN$IpUrdJVTS9/gRAADup0xmQ==$0" of type TABLE not found in
    schema "DWHOWN"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 2697
    ORA-06512: at "SYS.DBMS_METADATA", line 4220
    ORA-06512: at line 1

    ORA-31603: object "BIN$IpUrdJVTS9/gRAADup0xmQ==$0" of type TABLE not found in<br>This table come from the recycle bin. You maybe need to purge this one :<br>
    purge recyclebin;<br>
    Furthermore, it seems that you'll need to set long to bigger for more well output.<br>
    <br>
    Nicolas.

  • Using DBMS_METADATA.GET_DDL get error: ORA-00907: missing right parenthesis

    Hi,
    I'm trying to extract schema DDL from a database (10.2.0.4.0 - 64bit Enterprise Edition on Solaris 10). I run the query below and get an ORA-00907: missing right parenthesis error.
    SELECT DBMS_METADATA.GET_DDL( REPLACE(object_type,' ','_') AS object_type, object_name) FROM user_objects WHERE object_type NOT IN ('TABLE_PARTITION','INDEX_PARTITION','LOB');
    This is the output when running the above in sqlplus worksheet
    select DBMS_METADATA.GET_DDL( REPLACE(object_type,' ','_') as object_type, object_name) FROM user_objects where object_type not in ('TABLE_PARTITION','INDEX_PARTITION','LOB')
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    removing the where clause gives the following:
    select DBMS_METADATA.GET_DDL( REPLACE(object_type,' ','_') as object_type, object_name) FROM user_objects
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    Any pointers would be gratefully received. I know I could get the DDL out using exp/imp but I want to understand why I'm getting the missing parenthesis error.
    cheers,
    Ewan

    SELECT DBMS_METADATA.GET_DDL( REPLACE(object_type,' ','_') AS object_type, object_name) FROM user_objects WHERE object_type NOT IN You don't need an alias here. Get rid of " AS object_type" and it should work.

  • Bug in DBMS_METADATA.get_ddl?

    If you create the functions:
    CREATE OR REPLACE FUNCTION testingit1 RETURN NUMBER IS
    tmpVar NUMBER;
    BEGIN
    tmpVar := 0;
    RETURN tmpVar;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END testingit1;
    and
    CREATE OR REPLACE FUNCTION
    testingit2 RETURN NUMBER IS
    tmpVar NUMBER;
    BEGIN
    tmpVar := 0;
    RETURN tmpVar;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END testingit2;
    And use DBMS_METADATA.get_ddl to return the code. When the function was created with the name on a seperate line (testingit2) the code returned has the name repeated
    e..g., SELECT DBMS_METADATA.get_ddl('FUNCTION', 'TESTINGIT2')
    FROM dual
    returns
    "CREATE OR REPLACE FUNCTION "TESTUSER"."TESTINGIT2"
    testingit2 RETURN NUMBER IS
    tmpVar NUMBER; ..."
    Anyone seen this before and know how to fix it?

    using some sort of XML transform? Yes,
    SQL> create or replace function get_code return clob is
      2      l_xml XMLTYPE ;
      3      l_xsl XMLTYPE ;
      4  begin
      5      select XMLTYPE(dbms_metadata.get_xml('FUNCTION', 'TESTINGIT2')) into l_xml from dual ;
      6      l_xsl := XMLTYPE('<?xml version="1.0"?>'||
      7                   '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"'||
      8                   ' version="1.0"'||
      9                   ' result-ns=""'||
    10                   ' indent="no">'||
    11                   '<xsl:output method="text" media-type="text/text" indent="no"/>'||
    12                   '<xsl:template match="/">'||
    13                   'CREATE OR REPLACE <xsl:for-each select="//SOURCE_LINES/SOURCE_LINES_ITEM">'||
    14                   '<xsl:value-of select="./SOURCE" />'||
    15                   ' </xsl:for-each>'||
    16                   '</xsl:template>'||
    17                   '</xsl:stylesheet>') ;
    18      return(l_xml.transform(l_xsl).getCLOBVal()) ;
    19  end ;
    20  /
    Function created.
    SQL> select get_code from dual ;
    GET_CODE
    CREATE OR REPLACE FUNCTION
    testingit2 RETURN NUMBER IS
    tmpVar NUMBER;
    begin
    null ;
    end ;
    1 row selected.
    SQL>

  • Use of DBMS_METADATA.GET_DDL with respect to triggers

    We are very pleased with DMBS_METADATA for punching DDLs in general, We use the following to create executable scripts for recreating any object in our databases.
    SELECT DBMS_METADATA.GET_DDL('OBJECT_TYPE', 'OBJECT_NAME', 'SAINADM' ) from dual;
    In most types of object, the DDL produced can be executed without errors, providing that the original target object was well founded. However, we have found that in the case of a triggers, the DDL produced does not function for the following reason:
    EXAMPLE
    -- This set of instructions is produced by a metascript too complicated to show here
    SPOOL TRIGGER_NAME.trg
    SELECT DBMS_METADATA.GET_DDL('TRIGGER', 'TRIGGER_NAME', 'SCHEMA_NAME' ) txt
    FROM DUAL;
    SPOOL OFF
    END OF EXAMPLE
    This will produce the following output, spooled to the file TRIGGER_NAME.trg
    OUTPUT
    -- we have anonymised our object names
    -- the syntax is what I would like you to focus on
    CREATE OR REPLACE TRIGGER "SCHEMA_NAME"."TRIGGER_NAME"
    BEFORE INSERT on SCHEMA_NAME.TABLE_NAME FOR EACH ROW
    BEGIN
    select SCHEMA_NAME.SEQUENCE_NAME.nextval
    into :new.colname
    from dual;
    END;
    ALTER TRIGGER SCHEMA_NAME"."TRIGGER_NAME" ENABLE
    _END OF OUTPUT_
    Note what has happened.
    1. The trigger DDL has been produced
    2. So has a the ALTER TRIGGER ... ENABLE
    3. BUT => between the trigger DDL and the alter trigger statement the is no slash (of course, because naturally DBMS_METADATA does not produce such characters). BUT this is problematic, because the combination of the Create trigger statement and the alter trigger statement, without a slash in between means that the spool file is atomically illegal. Because in real life we need a slash between the two staements.
    Why is this a problem for us?
    - Because we are about to introduce the automation of object changes between our "Development" "Integration" "Quality Assurance" and "Production" databases based on the execution of files produced by DBMS_METADATA.GET_DDL. For every other type of object, the file produced is well founded and executable DDL that will create the object. But in the case of triggers, the existence of the alter trigger statement renders the foregoing create trigger statement unexecutable.
    The use of DMBS_METADATA is more or less vanilla. That is to say, there appears to be no scope for instructing DBMS_METADATA to abstain form including the alter trigger statement
    SELECT DBMS_METADATA.GET_DDL('TRIGGER', 'TRIGGER_NAME', 'SCHEMA_NAME' ) txt
    Here are my questions
    1. How can we punch the DDL for triggers without bringing the alter trigger statement
    2. Alternatively, how can we automate the insertion of the slash character in between the CREATE TRIGGER and the ALTER TRIGGER in the original metascript that creates the example spool file.
    Thanks for your attention. Every response will be welcomed.
    Edited by: user10248070 on Mar 2, 2010 3:54 AM

    You can use
    dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', TRUE );See http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10577/d_metada.htm#BGBJBFGE.
    Example:
    SQL> set long 1000
    SQL> set heading off
    SQL> select * from v$version;
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    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
    SQL> exec dbms_metadata.set_transform_param( DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', TRUE );
    PL/SQL procedure successfully completed.
    SQL> SELECT DBMS_METADATA.GET_DDL('TRIGGER', 'UPDATE_JOB_HISTORY', 'HR' ) txt
      2  FROM DUAL;
      CREATE OR REPLACE TRIGGER "HR"."UPDATE_JOB_HISTORY"
      AFTER UPDATE OF job_id, department_id ON employees
      FOR EACH ROW
    BEGIN
      add_job_history(:old.employee_id, :old.hire_date, sysdate,
                      :old.job_id, :old.department_id);
    END;
    ALTER TRIGGER "HR"."UPDATE_JOB_HISTORY" ENABLE;Edited by: P. Forstmann on 2 mars 2010 13:48

Maybe you are looking for

  • Jabber 9.6 Cannot Currently Add the Contacts

    I'm running Jabber for Windows 9.6 with Jabber Cloud (formerly WebEx Connect).  I have all my internal users in addition to a large number of external contacts including Cisco employees and some of my clients.  Today I was adding 2 contacts at anothe

  • No Phone Line and Broadband Speed at 0.2 - Not hap...

    Afternoon, I ordered the phone, TV, and Broadband with an activation date of the 5th December. I then received a text message to advise that a phone line engineer will visit between 1pm-6pm, I booked half a day off work but no one got in touch. At ab

  • Can't move image files within Bridge

    I recently bought an iMac and got the CS5 license transferred over to the Mac platform. Got CS5 loaded and everything works except for one critical thing: I can no longer move image files within Bridge. When I do the right click on an image file to s

  • Flex 4 beta tutorials great--but...

    I went through the tutorials at http://www.adobe.com/devnet/flex/articles/fcf_getting_started_coldfusion_flex_02.html and was very quickly able to get the sample (and some of my own cfc's) to work on my local pc. What I've been struggling with for da

  • Project system error

    hi all, this my query against budget error in project system in tcode sap_alr_87013558 i am finding that my budget is for 11100000, actual is 8116942,commitment is 511355,remord plan is 9597403,and available is 1502597 . please note that even i am ha