Using DBMS_METADATA

I'm trying to get to grips with DBMS_METADATA to transfer table DDL across schemas, making some modifications in the process.
Firstly, I'm not achieving table recreation using DBMS_METADATA.PUT. Example 18-7 from the Utilities manual is giving an "ORA-00942: Table does not exist" error, and my own attempt below does not result in a copy of the table being created. Can anyone point out what the problem is?
xdba@ora10gr2 > select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
xdba@ora10gr2 > create user king identified by lion;
User created.
xdba@ora10gr2 > grant connect, resource to king;
Grant succeeded.
xdba@ora10gr2 > declare
  2
  3    src   number;
  4    destn number;
  5
  6    xml   xmltype;
  7    ddls  sys.ku$_ddls;
  8
  9    txh number;
10
11    created boolean;
12    errs    sys.ku$_SubmitResults := sys.ku$_SubmitResults();
13
14    dbms_metadata_failure exception;
15
16  begin
17
18    src := dbms_metadata.open('TABLE');
19
20    dbms_metadata.set_filter(src, 'SCHEMA', 'SCOTT');
21    dbms_metadata.set_count(src, 3);
22
23    txh := dbms_metadata.add_transform(src, 'MODIFY');
24    dbms_metadata.set_transform_param(txh, 'OBJECT_ROW', 3);
25    dbms_metadata.set_remap_param(txh, 'REMAP_SCHEMA', 'SCOTT', 'KING');
26
27    txh := dbms_metadata.add_transform(src, 'DDL');
28
29    dbms_metadata.set_transform_param(txh, 'REF_CONSTRAINTS', false);
30    dbms_metadata.set_transform_param(txh, 'CONSTRAINTS', false);
31    dbms_metadata.set_transform_param(txh, 'STORAGE', false);
32    dbms_metadata.set_transform_param(txh, 'SEGMENT_ATTRIBUTES', false);
33
34    ddls := dbms_metadata.fetch_ddl(src);
35
36    for i in ddls.first()..ddls.last()
37    loop
38      dbms_output.put_line(ddls(i).ddlText);
39    end loop;
40
41    destn := dbms_metadata.openw('TABLE');
42
43    created := dbms_metadata.put(destn, xml, 0, errs);
44
45    dbms_metadata.close(destn);
46
47    if not created
48    then
49      raise dbms_metadata_failure;
50    end if;
51
52    dbms_metadata.close(src);
53
54  exception
55
56    when dbms_metadata_failure
57    then
58      for i in errs.first..errs.last
59      loop
60        for j in errs(i).errorlines.first..errs(i).errorlines.last
61        loop
62          dbms_output.put_line(errs(i).errorlines(j).errortext);
63        end loop;
64      end loop;
65      raise;
66
67  end;
68  /
CREATE TABLE "KING"."EMP"
   (    "EMPNO" NUMBER(4,0),
        "ENAME" VARCHAR2(10),
        "JOB" VARCHAR2(9),
        "MGR" NUMBER(4,0),
        "HIREDATE"
DATE,
        "SAL" NUMBER(7,2),
        "COMM" NUMBER(7,2),
        "DEPTNO" NUMBER(2,0)
PL/SQL procedure successfully completed.
xdba@ora10gr2 > connect king/lion@ora10gr2
Connected.
king@ora10gr2 > select dbms_metadata.get_ddl('TABLE', 'EMP') from dual;
ERROR:
ORA-31603: object "EMP" of type TABLE not found in schema "KING"
ORA-06512: at "SYS.DBMS_METADATA", line 1546
ORA-06512: at "SYS.DBMS_METADATA", line 1583
ORA-06512: at "SYS.DBMS_METADATA", line 1901
ORA-06512: at "SYS.DBMS_METADATA", line 2792
ORA-06512: at "SYS.DBMS_METADATA", line 4333
ORA-06512: at line 1Secondly, does anyone have experience of performing more complex transformations with DBMS_METADATA using external XLST? Are there any examples anywhere?

I've now achieved table recreation in example 18-7 and my own code above. This does not work when XMLType storage is used, but does when CLOB is used. It is not clear to me from these experiments and the documentation if there is intended to be a difference between XMLType/dbms_metadata.fetch_xml() and CLOB/dbms_metadata.fetch_clob, and if so, what this is?
I have also succeeded in applying more complex transformations using XSLT (changing table names, tablespaces; adding columns). However, I'm concerned that the dbms_metadata XML format seems to be undocumented.
Has there been any advance since XML Schema for Oracle DDL statements??
Can anyone shed any light on the use of the various <SPAREn> elements for example? Valid values for <COL_LIST_ITEM>...<TYPE_NUM>?

Similar Messages

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

  • 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

  • Getting table script using dbms_metadata.get_ddl, but with clob field

    So, Oracle 11g R2..
    I'm using dbms_metadata.get_ddl to get table scripts and it's working fine..
    now, I have a table with clob field, and it's not working... I got an 'missing right parenthesis (ora-0907)' error...
    I could paste a script that I got, but I don't think it makes any sense..
    does anybody have some experience on using this package on clob tables?
    tnx

    this is script that I got... it's long, and it looks like it's not good
    CREATE TABLE "COMMON"."TEST_AAA2"
       (    "ID" NUMBER(10,0),
        "TEKST" VARCHAR2(200 CHAR),
        "UPDATESTAMP" DATE,
        "OBJEKAT" CLOB,
         CONSTRAINT "TEST_PART_PK2" PRIMARY KEY ("ID")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "USERS"
      ALTER INDEX "COMMON"."TEST_PART_PK2"  UNUSABLE ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS  LOGGING
      STORAGE(
      BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
      NOCACHE LOGGING
      STORAGE(
      BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT))
      PARTITION BY RANGE ("UPDATESTAMP")
    (PARTITION "P_201012"  VALUES LESS THAN (TO_DATE(' 2011-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201101"  VALUES LESS THAN (TO_DATE(' 2011-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201102"  VALUES LESS THAN (TO_DATE(' 2011-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_ARCHIVE"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "COMMON_ARCHIVE" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201103"  VALUES LESS THAN (TO_DATE(' 2011-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201104"  VALUES LESS THAN (TO_DATE(' 2011-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_ARCHIVE"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "COMMON_ARCHIVE" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201105"  VALUES LESS THAN (TO_DATE(' 2011-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201106"  VALUES LESS THAN (TO_DATE(' 2011-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_ARCHIVE"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "COMMON_ARCHIVE" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_201107"  VALUES LESS THAN (TO_DATE(' 2011-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "COMMON_ARCHIVE" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS ,
    PARTITION "P_MAXVALUE"  VALUES LESS THAN (MAXVALUE)
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "COMMON_DATA"
    LOB ("OBJEKAT") STORE AS BASICFILE (
      TABLESPACE "COMMON_ARCHIVE" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
      NOCACHE LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) NOCOMPRESS )

  • Reverse engineer using DBMS_METADATA

    Hi,
    Can I use DBMS_METADATA package to reverse engineer a scheduled job from the database. I tried running below statement but it only returns the first job no matter what I do:
    select JOB,WHAT,dbms_metadata.get_ddl('JOB',USER) FROM DBA_JOBS
    I even used a where clause to make sure that I am using a specific job but the output remains same I mean I get statement generated only for first job.
    Any thought?
    Onkar

    Solomon Yakobson wrote:
    Gokhan Atil wrote:
    You may try to use DBMS_JOB.USER_EXPORT:I don't believe DBMS_JOB.USER_EXPORT is available in 9i.
    SY.Tested or guessing? Anyway, you can believe that it's available:
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE    9.2.0.8.0       Production
    TNS for Solaris: Version 9.2.0.8.0 - Production
    NLSRTL Version 9.2.0.8.0 - Production
    FUNCTION BACKGROUND_PROCESS RETURNS BOOLEAN
    PROCEDURE BROKEN
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    BROKEN                         BOOLEAN                 IN
    NEXT_DATE                      DATE                    IN     DEFAULT
    PROCEDURE CHANGE
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    WHAT                           VARCHAR2                IN
    NEXT_DATE                      DATE                    IN
    INTERVAL                       VARCHAR2                IN
    INSTANCE                       BINARY_INTEGER          IN     DEFAULT
    FORCE                          BOOLEAN                 IN     DEFAULT
    PROCEDURE INSTANCE
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    INSTANCE                       BINARY_INTEGER          IN
    FORCE                          BOOLEAN                 IN     DEFAULT
    PROCEDURE INTERVAL
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    INTERVAL                       VARCHAR2                IN
    FUNCTION IS_JOBQ RETURNS BOOLEAN
    PROCEDURE ISUBMIT
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    WHAT                           VARCHAR2                IN
    NEXT_DATE                      DATE                    IN
    INTERVAL                       VARCHAR2                IN     DEFAULT
    NO_PARSE                       BOOLEAN                 IN     DEFAULT
    PROCEDURE NEXT_DATE
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    NEXT_DATE                      DATE                    IN
    PROCEDURE REMOVE
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    PROCEDURE RUN
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    FORCE                          BOOLEAN                 IN     DEFAULT
    PROCEDURE SUBMIT
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          OUT
    WHAT                           VARCHAR2                IN
    NEXT_DATE                      DATE                    IN     DEFAULT
    INTERVAL                       VARCHAR2                IN     DEFAULT
    NO_PARSE                       BOOLEAN                 IN     DEFAULT
    INSTANCE                       BINARY_INTEGER          IN     DEFAULT
    FORCE                          BOOLEAN                 IN     DEFAULT
    PROCEDURE USER_EXPORT
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    MYCALL                         VARCHAR2                IN/OUT
    PROCEDURE USER_EXPORT
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    MYCALL                         VARCHAR2                IN/OUT
    MYINST                         VARCHAR2                IN/OUT
    PROCEDURE WHAT
    Argument Name                  Type                    In/Out Default?
    JOB                            BINARY_INTEGER          IN
    WHAT                           VARCHAR2                INRegards
    Gokhan

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Using dbms_metadata.get_ddl to capture the alter table

    Hi there,
    I know you can capture table ddl using dbms_metadata.get_ddl. However, I want to capture all the changes after the table got created. If you created a table then add one or more columns. I just want to capture the change as the new columns added.
    Here's an example.
    Create table test (id number, name varchar2(20);
    then
    alter table test add (type varchar2(40);
    I want to capture the syntax "alter table test add (type varchar(40)". Is this possible?
    Thanks

    I dont belive you could easily use dbma_metadata to do this... but you can use a database or schema level trigger e.g. :
    create or replace trigger test.test_trigger
    AFTER ALTER
    ON DATABASE
    DECLARE
    sql_text ora_name_list_t;
    v_stmt VARCHAR2(2000);
    n number;
    BEGIN
    n := ora_sql_txt(sql_text);
    FOR i IN 1..n
    LOOP
    v_stmt := v_stmt || sql_text(i);
    END LOOP;
    INSERT INTO test.test_table2
    VALUES
    (v_stmt);
    END;
    This will capture all alter commands fired at the database... so you would then need to filter them using the System-Defined Event Attributes see
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm#i1006211

  • To get rid of Schema name in output using DBMS_METADATA

    Hi all,
    Would someone be able to tell me how to get rid of the schema name output given by the below select stmt.
    Query
    Select Dbms_metadata.Get_ddl('FUNCTION','ACCOUNT_CODE')
    from dual;
    Result
    CREATE OR REPLACE FUNCTION "GOINGLIVE"."ACCOUNT_CODE" (PTransCode VarChar2,.............
    I checked for the documentation, but could manage to eliminate only storage clauses, tablespace etc. but not teh schema name.
    Please provide your advise on this.
    Thanks
    - Sandeep

    Which version are you on?
    In 10g, you can use DBMS_METADATA.SET_REMAP_PARAM to get rid of schema name:
    SQL> create table md_test(x int, y varchar2(10));
    Table created.
    SQL> declare
      2    l_ctx number;
      3    l_ctxt number;
      4    l_ddl sys.ku$_ddls;
      5  begin
      6    l_ctx := dbms_metadata.open('TABLE');
      7    dbms_metadata.set_filter(l_ctx, 'NAME', 'MD_TEST');
      8    l_ctxt := dbms_metadata.add_transform(l_ctx, 'MODIFY');
      9    dbms_metadata.set_remap_param(l_ctxt, 'REMAP_SCHEMA', user, null);
    10    l_ctxt := dbms_metadata.add_transform(l_ctx, 'DDL');
    11    dbms_metadata.set_transform_param(l_ctxt, 'SEGMENT_ATTRIBUTES', false);
    12    l_ddl := dbms_metadata.fetch_ddl(l_ctx);
    13    dbms_output.put_line(l_ddl(1).ddltext);
    14    dbms_metadata.close(l_ctx);
    15  end;
    16  /
    CREATE TABLE "MD_TEST"
       (    "X" NUMBER(*,0),
            "Y" VARCHAR2(10)
    PL/SQL procedure successfully completed.In 9i, you have to resort to some manual tricks (with REPLACE, probably):
    SQL> create table md_test(x int, y varchar2(10));
    Table created.
    SQL> declare
      2    l_ctx number;
      3    l_ctxt number;
      4    l_ddl sys.ku$_ddls;
      5  begin
      6    l_ctx := dbms_metadata.open('TABLE');
      7    dbms_metadata.set_filter(l_ctx, 'NAME', 'MD_TEST');
      8    l_ctxt := dbms_metadata.add_transform(l_ctx, 'DDL');
      9    dbms_metadata.set_transform_param(l_ctxt, 'SEGMENT_ATTRIBUTES', false);
    10    l_ddl := dbms_metadata.fetch_ddl(l_ctx);
    11    dbms_output.put_line(
    12      replace(l_ddl(1).ddltext, '"' || user || '".'));
    13    dbms_metadata.close(l_ctx);
    14  end;
    15  /
    CREATE TABLE "MD_TEST"
       (    "X" NUMBER(*,0),
            "Y" VARCHAR2(10)
    PL/SQL procedure successfully completed.
    SQL> select * from v$version where rownum = 1;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - ProductionHope this helps,
    Andrew.

  • Get DDL for uncrypted packages using DBMS_METADATA

    Hi all,
    i was wondering if i could extract DDL sources for only uncrypted packages in my database using DBMS_METADATA?
    i have a lot of crypted packages stored in the DB.
    thank you in advance for your help

    dodi wrote:
    mmm so there is no way i can do that :( too bad!What about something like this (note untested)?
    DECLARE
    BEGIN
            FOR r IN
                    SELECT  DISTINCT OWNER
                    ,       NAME
                    ,       TYPE
                    FROM    DBA_SOURCE WHERE
                    NOT REGEXP_LIKE(UPPER(TEXT),'(PROCEDURE|PACKAGE|PACKAGE BODY) (.*) WRAPPED')
                    AND OWNER NOT IN ('SYS','SYSTEM','SYSMAN') -- Or OWNER IN for a specific set of SCHEMAS
                    AND TYPE IN ('PROCEDURE','PACKAGE')
                    AND LINE = 1
            LOOP
                    /*EXECUTE IMMEDIATE 'SELECT DBMS_METADATA.GET_DDL(''' || r.TYPE || ''',''' || r.NAME || ''',''' || r.OWNER || ''') FROM DUAL';*/
                    DBMS_OUTPUT.PUT_LINE('SELECT DBMS_METADATA.GET_DDL(''' || r.TYPE || ''',''' || r.NAME || ''',''' || r.OWNER || ''') FROM DUAL');
            END LOOP;
    END;

  • Not able to create an object using dbms_metadata.put function

    Hi,
    I have the metadata of an object in one of my database table as xml. I failed to recreate the object in the other schema using metadata api. I developed a stored function to do the above job. My function doesn't throw any error meanwhile it doesn't create the object.
    My code snippet is
    CREATE OR REPLACE PROCEDURE DDI.move_table(
    table_name in VARCHAR2,
    from_schema in VARCHAR2,
    to_schema in VARCHAR2 )
    AUTHID CURRENT_USER
    IS
    -- Define local variables.
    h1 NUMBER; -- handle returned by OPEN
    h2 NUMBER; -- handle returned by OPENW
    th1 NUMBER; -- handle returned by ADD_TRANSFORM for MODIFY
    th2 NUMBER; -- handle returned by ADD_TRANSFORM for DDL
    xml XMLTYPE; -- XML document
    errs sys.ku$_SubmitResults := sys.ku$_SubmitResults();
    err sys.ku$_SubmitResult;
    result BOOLEAN;
    BEGIN
    SELECT REPOS INTO xml from ddi.ddi_repos_t where obj_id = '1801';
    -- Specify the object type using OPENW (instead of OPEN).
    h2 := DBMS_METADATA.OPENW('TABLE');
    -- First, add the MODIFY transform.
    th1 := DBMS_METADATA.ADD_TRANSFORM(h2,'MODIFY');
    -- Specify the desired modification: remap the schema name.
    DBMS_METADATA.SET_REMAP_PARAM(th1,'REMAP_SCHEMA',from_schema,to_schema);
    -- Now add the DDL transform so that the modified XML can be
    -- transformed into creation DDL.
    th2 := DBMS_METADATA.ADD_TRANSFORM(h2,'DDL');
    -- Call PUT to re-create the object.
    result := DBMS_METADATA.PUT(h2,xml,0,errs);
    DBMS_METADATA.CLOSE(h2);
    IF NOT result THEN
    -- Process the error information.
    FOR i IN errs.FIRST..errs.LAST LOOP
    err := errs(i);
    FOR j IN err.errorLines.FIRST..err.errorLines.LAST LOOP
    dbms_output.put_line(err.errorLines(j).errorText);
    END LOOP;
    END LOOP;
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    RAISE_APPLICATION_ERROR(-20510,'No xml is available as metadata');
    END;
    Could you tell me where is the probelm?
    The schema where i created and execute my function having dba privilege also.
    Regards,
    Madhavi.

    Hi Madhavi,
    The below code works for me:
    SQL> conn sys as sysdba
    Connected.
    SQL> select count(*) from dba_objects where object_name = 'DEPT' and owner = 'OE';
      COUNT(*)                                                                     
             0                                                                     
    SQL> CREATE OR REPLACE PROCEDURE move_table(
      2  table_name in VARCHAR2,
      3  from_schema in VARCHAR2,
      4  to_schema in VARCHAR2 )
      5  AUTHID CURRENT_USER
      6  IS
      7  -- Define local variables.
      8  h1 NUMBER; -- handle returned by OPEN
      9  h2 NUMBER; -- handle returned by OPENW
    10  th1 NUMBER; -- handle returned by ADD_TRANSFORM for MODIFY
    11  th2 NUMBER; -- handle returned by ADD_TRANSFORM for DDL
    12  xml clob; -- XML document
    13  errs sys.ku$_SubmitResults := sys.ku$_SubmitResults();
    14  err sys.ku$_SubmitResult;
    15  result BOOLEAN;
    16  BEGIN
    17 
    18  select DBMS_METADATA.GET_XML('TABLE','DEPT','SCOTT') into xml from dual;
    19 
    20  -- Specify the object type using OPENW (instead of OPEN).
    21  h2 := DBMS_METADATA.OPENW('TABLE');
    22 
    23  -- First, add the MODIFY transform.
    24  th1 := DBMS_METADATA.ADD_TRANSFORM(h2,'MODIFY');
    25 
    26  -- Specify the desired modification: remap the schema name.
    27  DBMS_METADATA.SET_REMAP_PARAM(th1,'REMAP_SCHEMA',from_schema,to_schema);
    28 
    29  -- Now add the DDL transform so that the modified XML can be
    30  -- transformed into creation DDL.
    31  th2 := DBMS_METADATA.ADD_TRANSFORM(h2,'DDL');
    32 
    33  -- Call PUT to re-create the object.
    34  result := DBMS_METADATA.PUT(h2,xml,0,errs);
    35 
    36  DBMS_METADATA.CLOSE(h2);
    37  IF NOT result THEN
    38 
    39  -- Process the error information.
    40  FOR i IN errs.FIRST..errs.LAST LOOP
    41  err := errs(i);
    42  FOR j IN err.errorLines.FIRST..err.errorLines.LAST LOOP
    43  dbms_output.put_line(err.errorLines(j).errorText);
    44  END LOOP;
    45  END LOOP;
    46  END IF;
    47  EXCEPTION
    48  WHEN NO_DATA_FOUND THEN
    49  RAISE_APPLICATION_ERROR(-20510,'No xml is available as metadata');
    50  END;
    51  /
    Procedure created.
    SQL> exec move_table('DEPT','SCOTT','OE');
    PL/SQL procedure successfully completed.
    SQL> select count(*) from dba_objects where object_name = 'DEPT' and owner = 'OE';
      COUNT(*)                                                                     
             1                                                                     
    SQL> spool off;The xml returned by the get_xml function contains the tablespace name and storage parameters of the schema in which the object is present.
    Check these parameters for both your schemas.

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

  • Using dbms_metadata to get defination of large table

    Hi,
    I have very very large table definition table with partitions and sub-partitions and I want to create that table in some other db.
    I am trying below spooled query but its not retrieving complete definition of the table, any other setting I should follow
    spool t.sql
    set pagesize 0
    set long 2000000
    select dbms_metadata.get_ddl
    I am using oracle 10g r2
    Thanks,
    Pankaj

    Thanks you all for your replied, following are observation after settings suggested
    With setting
    ==================
    set longchunksize 2000000
    set long 2000000
    set lines 2000
    set pages 0
    -sh-3.00$ cat t.sql | wc
    10819 23419 21635001
    =================
    With setting
    set long 100000
    set pages 0
    -sh-3.00$ cat t.sql | wc
    3452 7326 279269
    Result => None worked for me :(

  • Using DBMS_METADATA.PUT with large documents

    Hi all,
    I am using the DBMS_METADATA functions and procedures to programmatically store and re-creating database objects. All was working well until I ran into some large create scripts (particularly on partitioned indexes and tables). If I only have a few partitions, the DBMS_METADATA.PUT successfully creates the index, but if my table has 40 partitions, the DBMS_METADATA.PUT fails.
    I came across one post that indicated that this is the result of the EXECUTE_IMMEDIATE being restricted to 32K.
    If that is the case, has anyone successfully found a workaround that will allow me to recreate tables and indexes that have large create scripts.
    Thanks
    Steve

    Again a post with no version number so anyone trying to help has to guess.
    In 11g Oracle merged NDS and DBMS_SQL so that limit no longer exists. In previous versions back to, probably, 7.3.4 you can use the DBMS_SQL built-in package.
    Look at the example "execute_plsql_block" in Morgan's Library at www.psoug.org under DBMS_SQL.
    In 10gR2 and 11gR1, and possibly earlier versions but I do not recall, dbms_metadata.put has a clob option. Look at the demo, again, in Morgan's Library under the package's name.
    But if the point is partitioned indexes be sure you familiarize yourself with DBMS_PCLXUTIL too.

Maybe you are looking for

  • How do i search for a specific email in mail.

    I would like to know how do i search my inbox for an email that was sent more than a week ago. There is no search optin, or a "sort by" option as in mails on an i-Mac.

  • HT201343 Can I Airplay from my mac to my apple Tv and disable the Mac screen to take workload off the graphics card?

    Wondering if it's possible to enable mirroring and so the mac mini only sends what would be on its own screen to the appleTV with just an exit airplay or similar on the mac screen.

  • Basic Database Queries

    Q .what is difference between database and database warehouse? Q. what is difference between postgres and postgres sql? Q. What are other databases and query language available ? Q. what is difference between sql, postgres sql, oracle, postgres, Mysq

  • Problem viewing logged-in users

    I have Cisco Secure ACS Solution Engine v3.3. I have configured it to authenticate users agains Microsoft Active Directory Windows 2003. In The server i have installed Remote Agent. In Reports and Activity i can see Passed Authenticactions, but when

  • Quasi Blue-Screen after installing OS 10.5.1

    Ran D/U Repair Disk Permissions (no errors). Installed Leopard. All OK. Ran repair Disk Permissions from installation DVD. No errors. Imported OS 10.5.1 (only). Upon rebooting system came up with a "Software Update" tag which read "Installing 1 Item"