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

Similar Messages

  • DBMS_METADATA.GET_DDL performance

    Hi
    My application need to run on a schema and get all the DDL of the schema objects.
    This action is very heavy on the server and I get 100% on the server CPU.
    my code look something like this:
    SELECT
    D.OBJECT_NAME,
    D.OBJECT_TYPE,
    TRIM(SYS.DBMS_METADATA.GET_DDL(REPLACE(REPLACE(OBJECT_TYPE,'DATABASE LINK','DB_LINK'),' ','_'),OBJECT_NAME,USER)) AS OBJECTCREATIONSCRIPT
    FROM SYS.USER_OBJECTS D
    INNER JOIN TEMPOBJECTSLIST OL
    ON OL.DBOBJECT_NAME = D.OBJECT_NAME
    AND OL.DBOBJECT_TYPE = D.OBJECT_TYPE
    WHERE OBJECT_TYPE IN('TABLE', 'VIEW', 'FUNCTION', 'PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'SEQUENCE', 'TYPE', 'SYNONYM', 'MATERIALIZED VIEW', 'DATABASE LINK', 'TYPE BODY', 'TRIGGER')
    Is ther any way to do this faster?
    I was thinking on some ways but I do not know how to implement them:
    1. working on paralel CPU - The action acording to Enterprise Manager is taking 100% of 1 of 4 CPUs.
    2. Add some indexes or run statistics on some where in the database.
    3. some other options...
    thanks

    Thanks, But I can't use an incremental table for this action becouse of some business logical restrictions of my application.
    the application need to do the same action as GET_DDL for all the schema objects like one schema snapshot.
    I have a new idea of solving this issue, perhaps someone could help me who to implement it (if it possible):
    DMBS_METATDATA package has a procedure GET_XML this procedure is match faster than GET_DDL.
    Is ther any way to convert the XML result of GET_XML to a DDL script?
    Edited by: rronen on 00:06 01/09/2010
    Edited by: rronen on 00:06 01/09/2010

  • 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 not working in 11g

    Hi All,
    I need a quick help from you. Following is not working in 11g.
    dbms_metadata.get_ddl( 'MATERIALIZED_VIEW', Mview_name, owner )
    It is throwing me an error saying the Materialized view does not exist, though its exist.
    Please let me know, what is wrong here with 11g.

    Please let me know, what is wrong here with 11g.No problem here: Can you reproduce these steps:
    SQL> select * from v$version where rownum = 1
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production         
    1 row selected.
    SQL> create materialized view mv_dummy as select * from dual
    Materialized View created.
    SQL> select dbms_metadata.get_ddl ('MATERIALIZED_VIEW', 'MV_DUMMY', user) ddl from dual
    DDL                                                                            
      CREATE MATERIALIZED VIEW "MICHAEL"."MV_DUMMY" ("DUMMY")                      
      ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOG
    GING                                                                           
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645        
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)             
      TABLESPACE "USERS"                                                           
      BUILD IMMEDIATE                                                              
      USING INDEX                                                                  
      REFRESH FORCE ON DEMAND                                                      
      USING DEFAULT LOCAL ROLLBACK SEGMENT                                         
      USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE                             
      AS select * from dual                                                        
    1 row selected.?

  • Spool Command with dbms_metadata.GET_DDL function

    Hi All,
    My requirement is before applying a patch on the Database Schema, I need to take a backup of the db objects DDL script, so that incase if I want to rollback I can use it. what I am trying to use is the dbms_metadata.GET_DDL function to get the DDL script and with the help of spool command store that in a text file.
    The problem I am encountering is the whole script runs without an error but whne I check the spool file for certain big packages the DDL script is not fully exported. The below is the script that I make use of to generate the DDL script.
    set heading off
    set feedback off
    set echo off
    set term off
    set newpage none
    set space 0
    set trimout on
    set TRIMSPOOL ON
    column c1 format a4000
    set long 99999
    set lines 1000
    exec DBMS_METADATA.SET_TRANSFORM_PARAM (DBMS_METADATA.SESSION_TRANSFORM, 'PRETTY', true);
    spool c:\Rollback.sql
    select dbms_metadata.GET_DDL('FUNCTION',u.object_name) || '/' c1
    from user_objects u
    where object_type = 'FUNCTION'
    and object_name in ('FN_CALCMASTERDATA_AGE','FUNC_ASSIGNBENEFITSNONFLEX','FUNC_CHECKNEWEMPLOYEE');
    select dbms_metadata.GET_DDL('PACKAGE_SPEC',u.object_name) || '/' c1
    from user_objects u
    where object_type = 'PACKAGE'
    and object_name in('PKGT_BEN_YEAR_DETL','PKGT_BENS_TEST');
    select dbms_metadata.GET_DDL('PACKAGE_BODY',u.object_name) || '/' c1
    from user_objects u
    where object_type = 'PACKAGE'
    and object_name in ('PKGT_BEN_YEAR_DETL','PKGT_BENS_TEST','PKGT_FLEX_INITIALIZATION','PKGT_EMP');
    spool off
    Note: Database Oracle 10 g,
    Client Machine Windows XP from where the script is ran.
    Is there any limitation in amount of data that can be spooled? or is there is any better way to accomplish this task, please help.
    Thanks
    Saami

    set long longer ;-)
    set long 1000000 longchunksize 1000000 linesize 32000 pagesize 0

  • Error while using DBMS_METADATA.GET_DDL package.

    Hi all,
    I want script of DDL of all tables in Database not in particular schema,
    As I am using below query
    SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
    FROM ALL_TABLES u
    WHERE u.nested='NO'
    AND (u.iot_type is null or u.iot_type='IOT')
    but it gives error as below.
    ORA-31603: object "ICOL$" of type TABLE not found in schema "SCOTT"
    It should give DDL of all tables, also I am not having DBA Privs.
    Please help me.
    Thanks & Regards
    Rajiv.

    It could be helpful if you have a look into [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1016867]documentation.
    Security Model
    The object views of the Oracle metadata model implement security as follows:
    Nonprivileged users can see the metadata of only their own objects.
    SYS and users with SELECT_CATALOG_ROLE can see all objects.
    Nonprivileged users can also retrieve public synonyms, system privileges granted to them, and object privileges granted to them or by them to others. This also includes privileges granted to PUBLIC.
    If callers request objects they are not privileged to retrieve, no exception is raised; the object is simply not retrieved.
    If nonprivileged users are granted some form of access to an object in someone else's schema, they will be able to retrieve the grant specification through the Metadata API, but not the object's actual metadata.
    In stored procedures, functions, and definers-rights packages, roles (such as SELECT_CATALOG_ROLE) are disabled. Therefore, such a PL/SQL program can only fetch metadata for objects in its own schema. If you want to write a PL/SQL program that fetches metadata for objects in a different schema (based on the invoker's possession of SELECT_CATALOG_ROLE), you must make the program invokers-rights.
    Best regards
    Maxim

  • Stange error when using dbms_metadata.get_ddl in PL/SQL procedure

    Basic info:
    Oracle 10.2.0.4.0 on linux.
    I'm trying to extract ddl of indexes that I drop and recreate frequently during monthly loads and store it in a table.
    This statement works on the command line:
    insert into saved_indexes
    select index_name,dbms_metadata.get_ddl('INDEX',index_name,owner_name)
    from sys.all_indexes
    where owner = owner_name
    and table_name = table_name;
    commit;
    The table 'saved_indexes' is a two column table with a varchar2(40) and a CLOB.
    When I use the following procedure, I get 'ORA-04044 procedure, function, package, or type is not allowed here -4044' every time.
    PROCEDURE SAVE_INDEXES (v_table IN VARCHAR2, v_owner IN VARCHAR2) IS
    v_errorcode number(8);
    v_errortext varchar2(1000);
    v_start_time date;
    BEGIN
    insert into saved_indexes
    select index_name,dbms_metadata.get_ddl('INDEX',index_name,v_owner)
    from sys.all_indexes
    where owner = v_owner
    and table_name = v_table;
    commit;
    EXCEPTION
    WHEN others THEN
    v_errorcode := sqlcode;
    v_errortext := substr(sqlerrm, 1, 1000);
    dbms_output.put_line(v_errortext || ' ' || v_errorcode);
    END;
    Alternatively I have tried it this way:
    PROCEDURE SAVE_INDEXES (v_table IN VARCHAR2, v_owner IN VARCHAR2 ) IS
    v_errorcode number(8);
    v_errortext varchar2(1000);
    v_index_ddl CLOB;
    BEGIN
    for x in (select index_name
    from sys.all_indexes
    where owner = v_owner
    and table_name = v_table)
    loop
    select dbms_metadata.get_ddl('INDEX',x.index_name,v_owner) into v_index_ddl from dual;
    insert into saved_indexes
    values(v_table,v_index_ddl);
    end loop;
    commit;
    EXCEPTION
    WHEN others THEN
    v_errorcode := sqlcode;
    v_errortext := substr(sqlerrm, 1, 1000);
    dbms_output.put_line(v_errortext || ' ' || v_errorcode);
    END;
    Always with the same result. I have poured over the documentation on this and have not found anything. All objects are in the same schema, so there is not an issues with invokers rights, or privileges.
    Any suggestions would be helpful...

    qwe11126 wrote:
    When I use the following procedure, I get 'ORA-04044 procedure, function, package, or type is not allowed here -4044' every time.There is nothing wrong with SP. Post a snippet of SQL*Plus code showing how you call SP along with errors.
    SY.

  • Calling DBMS_METADATA.GET_DDL on scheduler jobs owned by SYS

    Hi!
    While I can generally retrieve the DDL for scheduler jobs using the PROCOBJ type, this doesn't seem to work for scheduler jobs owned by SYS.
    Does anybody happen to have a workaround for this?
    SELECT user FROM dual
    USER
    SYS
    1 row selected
    select * from v$version
    BANNER                                                         
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production        
    5 rows selected
    SELECT DBMS_METADATA.GET_DDL('PROCOBJ' ,'MGMT_CONFIG_JOB', 'ORACLE_OCM') DDL FROM dual
    DDL
    BEGIN dbms_scheduler.create_job( ...
    1 row selected
    SELECT DBMS_METADATA.GET_DDL('PROCOBJ' ,'AUTO_SPACE_ADVISOR_JOB', 'SYS') DDL FROM dual
    ORA-31603: object "AUTO_SPACE_ADVISOR_JOB" of type PROCOBJ not found in schema "SYS"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 2806
    ORA-06512: at "SYS.DBMS_METADATA", line 4333
    ORA-06512: at line 1Cheers,
    Marcus

    I guess I need SELECT_CATALOG_ROLE role
    http://www.orafaq.com/node/807
    SYS and users with SELECT_CATALOG_ROLE can see all objects.

  • 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

  • Dbms_metadata.get_ddl returns unusable create index statement

    Hello everybody,
    I'm trying to write a procdeure that automatically deletes all duplicate record and rebuild all table indexes after an sqlldr load with direct path.
    In short the procdeure indentifies the indexes, read them using dbms_metadata.get_ddl('INDEX', 'IDX_UNIQUE_TEST') drops them, deletes the duplicated records and then recreates the indexes.
    However after the sqlldr, get_ddl function returns the following result:
    CREATE UNIQUE INDEX "MYUSER"."IDX_UNIQUE_TEST" ON "EDWH"."FOREX_ORD_PRC_INTRADAY" "C_ORD_TYP", "C_ORD", "D_INI_VAL", "C_PRC_TYP")
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "MYTABLESPACE"
    ALTER INDEX "MYUSER"."IDX_UNIQUE_TEST"  UNUSABLE
    As you can see there is an ALTER INDEX at the end that makes the whole statement invalid.
    Has anyone already seen that? I've tried to google it but with no chance. Help with this would really be appreciated.
    Thanks in advance
    Ross

    Mmh, yes it is unusable before the get_ddl, but how comes it returns both the create index and the alter index unusable statements?
    I've tried to make the index unusable with the alter index ... unusable statement but get_ddl still returned the create index only.
    I'm guessing that production server (10.2.0.4.0) is behaving differently from test machine (9.2.0.4.0). Any idea on that?
    Ross

  • 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.

  • Error when running dbms_metadata.get_ddl on different as logged in schema

    Hi ,
    I am running 10gR2 and trying to export views from different schema as logged in by using dbms_metadata.get_ddl.
    Now I logged as user 'USER_01' and run query like :
    SELECT dbms_metadata.get_ddl('TABLE','MY_TABLE', 'USER_01') FROM DUAL;
    I get the my_table definition,
    but if I stay logged in as USER_01 and try to get table definitions for YOUR_TABLE from schema USER_02 like
    SELECT dbms_metadata.get_ddl('TABLE','YOUR_TABLE', 'USER_02') FROM DUAL;
    -> I do get following error message:
    ORA-31603: object "YOUR_TABLE" of type TABLE not found in schema "USER_02"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 2805
    ORA-06512: at "SYS.DBMS_METADATA", line 4333
    ORA-06512: at line 1
    Do I need additional GRANTS on USER_02?
    Thanks

    I guess I need SELECT_CATALOG_ROLE role
    http://www.orafaq.com/node/807
    SYS and users with SELECT_CATALOG_ROLE can see all objects.

  • 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 in dbms_metadata.get_ddl ...

    Hi,
    I am using
    "Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    PL/SQL Release 9.2.0.6.0 - Production" .
    I am trying to Execute dbms_metadata.get_ddl to get the table structure
    select dbms_metadata.get_ddl( 'TABLE', 'EMP', 'SCOTT' ) from dual ;
    I am getting following error
    ERROR:
    ORA-06502: PL/SQL: numeric or value error
    ORA-31605: the following was returned from LpxXSLResetAllVars in routine
    kuxslResetParams:
    LPX-1: NULL pointer
    ORA-06512: at "SYS.UTL_XML", line 0
    ORA-06512: at "SYS.DBMS_METADATA_INT", line 3430
    ORA-06512: at "SYS.DBMS_METADATA_INT", line 4259
    ORA-06512: at "SYS.DBMS_METADATA", line 458
    ORA-06512: at "SYS.DBMS_METADATA", line 615
    ORA-06512: at "SYS.DBMS_METADATA", line 1221
    ORA-06512: at line 1
    Can any one help me in this regard how to overcome the Error ?
    Thanks in Advance
    Venkatesh .P

    Hi,
    There was a bug #2736436 in 9.2.0.1 and 9.2.0.5 :
    If a constraint is against a partitioned table then DBMS_METADATA.GET_DDL returns ORA-31605 and LPX-410 when attempting to get the DDL of the constraint.
    Seems to be solve in 9.2.0.6 patchset.
    Hmm, it seems that you're already in 9.2.0.6...
    Nicolas.

  • 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.

Maybe you are looking for

  • How can I get a single ID for all accounts?

    My migration from Mobile.me to iCloud has been a exercise in frustration. I log into the Apple site with a .me address, my apple id is a .mac address. I log into iTunes with a different id and password.  If I buy an app on the iPhone it won't sync to

  • XI message data

    Hi All, We are currently facing a scenario which is required to get all the message data( XML data from the messages) processed through few interfaces in an XI system. Do we have any tools or  methods available to download  the  message data from xi

  • Hooking up ipod

    everytime i try to connect my new ipod it says i have to restore and then i get a error message 1418. it now says i am stuck in a reprogram or something. if anyone can help me i sure would appreciate it.

  • Upload photo & MYSQL

    Hi I wanna create php code ton insert some info in MYSQL BDD, dreamweaver do that but I must upload image too with this, I choose file for this but it juste take name and I wanna upload photo in "images" directory with PHPMYADMIN, defaut value for im

  • Itunes says iam logged in on another computer but iam not so I cant get on my account

    Iam not on anyother computer with itunes and it wont let me get on the account, what do I do?