Issue in dbms_metadata.set_transform_param , SQLTERMINATOR Property

Hi,
I am using the dbms_metadata to get the DDL for all the objects in a particular schema.
DDL is retrieved without any issue, but the SQLTERMINATOR  is not added in end of any DDL.
The property used is
  dmsf := dbms_metadata.session_transform;
  dbms_metadata.set_transform_param(dmsf, 'SQLTERMINATOR', TRUE);
Please let me know on what should i change to fix this issue.
Below is the set of 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'))));

Please mark this question ANSWERED as it is a duplicate of the thread you posted in the Database General forum:
Issue in dbms_metadata.set_transform_param , SQLTERMINATOR Property

Similar Messages

  • Possible Issue with help for "disable property node"

    Hi, In Labview version 9.0 (32-bit) there seems to be a conflict between help info for the Enum constant  as applied to the disable property node . If I right click on a control variable and select create-> property node -> disable. If I then right click on disable -> help for disable, the help lists the following interger assignment 0 - Disable, 1- Disable and Greyed, 2 Enable. If however, I right click on the generated Enum constant and select properties -> Edit Items, the listing order is as follows; 0- Enable, 1- Disable, 2- Disable and Greyed. The latter assignment is how the Enum constant actually works. It appears that the help information may be incorrect.
    Regards,
    Pat    
    Solved!
    Go to Solution.

    Hi,
    I compared it with 8.2.
    In 8.2 creating a constant, indicator or control by right clicking on the "disabled" property node gave an object of type U8, which operates in accordance with the "help for disabled", ie
    0=Enable
    1=Disable
    2=Disable/grey
    In 9.0/2009 right clicking and creating on the property node gives an Enum (of datatype U8) with names/values in agreement with 8.2, and operation as in 8.2, BUT the "help for disabled" message says
    0=Disable
    1=Disable/grey
    2=Enable
    Thus I would agree that this is a documentation error, and the LabVIEW is correct.
    N.I. Can we have a CAR please?
    P.S. I do think that it is a good idea to have made the disabled property an enum, whilst maintaining compatability with previous code. I always wondered why it wasn't that way in earlier revisions.

  • ARB Issue: SDK Property Metadata

    Posted today:
    SDK Property Metadata
    Please comment by tomorrow morning, Friday May 1st. Thanks!

    Hi
    I think dbms_metadata.session_transform is for functions GET_DDL, GET_DEPENDENT_DDL, and GET_GRANTED_DDL only.
    You need to use set_transform_param on htransddl handle. Add this after line 65:
          dbms_metadata.set_transform_param (htransddl, 'PRETTY', true);
          dbms_metadata.set_transform_param (htransddl, 'SQLTERMINATOR', true);
    Other transform attributes like TABLESPACE and STORAGE should also be applied to htransddl so lines 40-45 can be removed.
    You must also add some logic when setting this transform parameters as STORAGE and TABLESPACE for example can not be applied to PACKAGE object type.
    Regards,
    Mitja

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

  • Not able to append "/" with dbms_metadata.

    Hi All,
    I am using 11gr2 and need to generate ddl for objects grants . i order to do this , I am using dbms_metadata to generate it. I need to add "/" after each command , but it's only adding to last page of the grants. also, even the linsize has been set to 200, but the output is still 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"Edited by: user11983993 on Jul 3, 2012 8:10 AM

    Hi,
    You have to use dbms_metadata.set_transform_param in order 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.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

  • How to put the ";" at the end when using dbms_metadata.get_ddl?

    Hi there,
    Is there a to put the semicolon ";" at the end of each DDL when I use dbms_metadata.get_ddl for (TABLE or TRIGGER)?
    Thanks

    Use:
    exec dbms_metadata.set_transform_param(DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', TRUE );

  • 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;
    /

  • Using dbms_metadata to get ddl for creating directories

    Hi,
    I am working on creating a test database, which is a copy of production for 11g upgrade testing. I want to get all the ddls from my production databse to create all the directories in the new test database. I have been trying to use dbms_metadata for this -
    Below is the code that I have been trying to use. However, when I query the my_metadata table, there is nothing in there. Can someone please help me with this?
    DROP TABLE my_metadata;
    CREATE TABLE my_metadata(md CLOB);
    CREATE OR REPLACE PROCEDURE progp1_directories_extract
    AS
    hndl NUMBER; --dbms_metadata handle
    th NUMBER; --transform handle
    DDL CLOB; --individual clobs extracted from the database
    BEGIN
    hndl := DBMS_METADATA.OPEN ('DATABASE_EXPORT'); --Open the metadata
    DBMS_METADATA.set_filter (hndl, 'INCLUDE_PATH_EXPR', '=''DIRECTORY'''); --Filter data as appropriate
    th := DBMS_METADATA.add_transform (hndl, 'DDL'); --Get the Transform Handle
    DBMS_METADATA.set_transform_param (th, 'SQLTERMINATOR', TRUE); --Include the semicolon
    LOOP
    DDL := DBMS_METADATA.fetch_clob (hndl); --Loop through the result set, inserting into our temp table
    EXIT WHEN DDL IS NULL;
    INSERT INTO my_metadata
    (md)
    VALUES (DDL);
    COMMIT;
    END LOOP;
    DBMS_METADATA.CLOSE (hndl);
    EXCEPTION
    WHEN OTHERS
    THEN
    NULL;
    END;
    show errors

    user12158503 wrote:
    Below is the code that I have been trying to use. However, when I query the my_metadata table, there is nothing in there. Can someone please help me with this?
    DROP TABLE my_metadata;
    CREATE TABLE my_metadata(md CLOB);
    CREATE OR REPLACE PROCEDURE progp1_directories_extract
    AS
    hndl   NUMBER; --dbms_metadata handle
    th     NUMBER; --transform handle
    DDL    CLOB;   --individual clobs extracted from the database
    BEGIN
    hndl := DBMS_METADATA.OPEN ('DATABASE_EXPORT'); --Open the metadata
    DBMS_METADATA.set_filter (hndl, 'INCLUDE_PATH_EXPR', '=''DIRECTORY'''); --Filter data as appropriate
    th := DBMS_METADATA.add_transform (hndl, 'DDL'); --Get the Transform Handle
    DBMS_METADATA.set_transform_param (th, 'SQLTERMINATOR', TRUE); --Include the semicolon
    LOOP
    DDL := DBMS_METADATA.fetch_clob (hndl); --Loop through the result set, inserting into our temp table
    EXIT WHEN DDL IS NULL;
    INSERT INTO my_metadata
    (md)
    VALUES (DDL);
    COMMIT;
    END LOOP;
    DBMS_METADATA.CLOSE (hndl);
    EXCEPTION
    WHEN OTHERS
    THEN
    NULL;
    END;
    show errors
    I can't see the bit where you actually try to execute the procedure - I assume you are doing this.
    One killer feature of your code is the "when others then null" - you're not going to know where and why your code failed.
    Taking a guess: are you running this as SYS ? If not then it's possible that you're not finding any data because of some feature in the way that the code sees the directory objects - they're always owned by SYS.
    Although your code (when corrected) will generate the grants on the directories, the following is sufficient to generate the "create directory" statements. (Since all directories are owned by SYS it's actually an error to reference an owner in this query -- that means, by the way, that the answer you've marked as correct doesn't actually work).
    select
         dbms_metadata.get_ddl('DIRECTORY',directory_name)
    from
         dba_directories
    ;Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
    There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.)
    +"I believe in evidence. I believe in observation, measurement, and reasoning, confirmed by independent observers. I'll believe anything, no matter how wild and ridiculous, if there is evidence for it. The wilder and more ridiculous something is, however, the firmer and more solid the evidence will have to be."+
    Isaac Asimov                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • DBMS_Metadata package wrapping lines

    How can you set the line size for the DDL that is generated from the DBMS_MetaData pkg? If I try to run the script that is generated by this output, I get errors because things are wrapped.
    I used this sql to generate my ddl:
    select dbms_metadata.get_ddl('TABLE','EMP') FROM DUAL;
    Anybody have a good idea on how to get this output to work properly?
    Thanks,
    Jim

    Setting LONG does not help wrapping lines, use LINESIZE and COLUMN FORMAT.
    I am using this script:
    PROMPT exporting &1. &2..&3.
    --##&1=OBJECT_TYPE &2=OWNER &3=OBJECT_NAME
    set echo off
    set linesize 1000
    set long 65536
    set trimspool on
    set null null
    set head off
    set pagesize 0
    set newpage none
    set headsep off
    set feedback off
    set ver off
    set pause off
    set flush off
    column aaa format a1000
    EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',true);
    spool &Your_package.sql
    select dbms_metadata.get_ddl('PACKAGE', '&Your_package', '&OWNER') aaa from dual
    spool off

  • 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

  • Dbms_metadata and trigger ddl (db version 10g)

    Hi all,
    does anyone know if there is a parameter in procedure dbms_metadata.set_transform_param to get rid of the alter trigger enable clause that is automatically appended otherwise?
    For other objects like table there is such possibility for constraints for instance, but I don't see triggers in the list of supported objects.
    Thanks and Bye,
    Flavio

    Hi All,
    According to the support, we update the column flag in mlog$ to fix the issue due to the Bug 12849688.
    Now, DBMS_METADATA.get_dependent_ddl can return the right result.
    However, the old data in the materialized view log cannot be cleared after different kinds of refresh including fast, complete and force etc.
    Any idea?
    Thanks for your help

  • Dbms_metadata for 381 triggers

    I am trying to extract 381 triggers into a file that I can then run to recreate the triggers later.
    But when I run the result of the file I get from below, it doesn't compile the triggers.
    The below script does not place an '/' at the end of eacj SQl statement.
    It does this at the end of the DDLs...
    END zedw_trg_adr6;
    ALTER TRIGGER "SAPSR3"."ZEDW_TRG_ADR6" ENABLE
    instead of ...
    END zedw_trg_adr6;
    ALTER TRIGGER "SAPSR3"."ZEDW_TRG_ADR6" ENABLE
    How can I fix the commands below?
    I am using this to creat ethe file of trigger DDls to run later.
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    sqlplus "/ as sysdba"
    SET LONGCHUNKSIZE 1024
    SET LONG 128000
    SET ECHO OFF
    SET HEADING OFF
    SET LINESIZE 512
    SET TRIMOUT ON
    SET TRIMSPOOL ON
    SET WRAP ON
    spool c:\temp\triggers_extract.sql
    select dbms_metadata.GET_DDL(u.object_type,u.object_name,'SAPSR3')
    from dba_objects u
    where object_type = 'TRIGGER'
    and owner = 'SAPSR3' ;
    spool off;
    exit
    vi triggers_extract.sql
    -- Remove any 'SQL>' lines at the top & bottom of the script.
    :wq!
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Hi Bill,
    Try playing a little with this:
    dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);Edit:
    Also, you should either place all your SQL*Plus commands inside a script and then execute that after logging in.
    Or, set termout off.
    Both should remove the need for afterward editing.
    Regards
    Peter
    Edited by: Peter on Dec 6, 2011 3:13 PM

  • Export fails in DBMS_METADATA.FETCH_XML_CLOB

    Hello,
    I am unable to export a schema using Enterprise Manager. After the job is
    successfully submitted, the job status is failed. The first reported error
    is:
    ORA-39125: Worker unexpected fatal error in
    KUPW$WORKER.GET_TABLE_DATA_OBJECTS while calling
    DBMS_METADATA.FETCH_XML_CLOB []
    The last 2 errors reported are:
    ORA-04063: package body "DMSYS.DBMS_DM_UTIL" has errors
    ORA-06508: PL/SQL: could not find program unit being called
    Any suggestions are appreciated.
    Thanks,
    Griff
    Here are more details:
    * The schema I want to export is big (.dbf file is 10G). Many of the
    tables in the schema include columns of type CLOB.
    * The PL\SQL generated by Enterprise Manager to carry out the export:
    declare
    h1 NUMBER;
    begin
    begin
    h1 := dbms_datapump.open (operation => 'EXPORT', job_mode => 'SCHEMA',
    job_name => 'CraigtestExportJobName3', version => 'COMPATIBLE');
    end;
    begin
    dbms_datapump.set_parallel(handle => h1, degree => 4);
    end;
    begin
    dbms_datapump.add_file(handle => h1, filename => 'EXPDAT.LOG',
    directory => 'GRIFF_ORADATA_DIR', filetype => 3);
    end;
    begin
    dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value
    => 0);
    end;
    begin
    dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR',
    value => 'IN(''CRAIGTEST'')');
    end;
    begin
    dbms_datapump.set_parameter(handle => h1, name => 'ESTIMATE', value =>
    'BLOCKS');
    end;
    begin
    dbms_datapump.add_file(handle => h1, filename =>
    'EXPDAT_CRAIGTEST_03.DMP', directory => 'GRIFF_ORADATA_DIR', filetype => 1);
    end;
    begin
    dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA',
    value => 1);
    end;
    begin
    dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD',
    value => 'AUTOMATIC');
    end;
    begin
    dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step =>
    0);
    end;
    begin
    dbms_datapump.detach(handle => h1);
    end;
    end;
    The "Output Log" page says:
    ORA-39125: Worker unexpected fatal error in
    KUPW$WORKER.GET_TABLE_DATA_OBJECTS while calling
    DBMS_METADATA.FETCH_XML_CLOB []
    ORA-31642: the following SQL statement fails:
    BEGIN
    DMSYS.DBMS_DM_MODEL_EXP.SCHEMA_CALLOUT('CRAIGTEST',0,1,'10.01.00.02.00');
    END;
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
    ORA-06512: at "SYS.DBMS_METADATA", line 872
    ORA-04063: package body "DMSYS.DBMS_DM_UTIL" has errors
    ORA-06508: PL/SQL: could not find program unit being called
    * I researched the error and found
    Re: Error while taking dump using datapump
    Following the advice, I ensured that the DMSYS user account is unlocked. I
    continued to get the same errors.

    Hi
    I think dbms_metadata.session_transform is for functions GET_DDL, GET_DEPENDENT_DDL, and GET_GRANTED_DDL only.
    You need to use set_transform_param on htransddl handle. Add this after line 65:
          dbms_metadata.set_transform_param (htransddl, 'PRETTY', true);
          dbms_metadata.set_transform_param (htransddl, 'SQLTERMINATOR', true);
    Other transform attributes like TABLESPACE and STORAGE should also be applied to htransddl so lines 40-45 can be removed.
    You must also add some logic when setting this transform parameters as STORAGE and TABLESPACE for example can not be applied to PACKAGE object type.
    Regards,
    Mitja

  • 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

Maybe you are looking for