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

Similar Messages

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

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

  • 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

  • Extract DDL for Partitioned tables in Oracle 8i

    Hi
    I am currently working on an Oracle 8i database. I have a need to extract the DDL of the existing tables & indexes. Dont need a schema level DDL extract, i just need it for a couple of tables and the corresponding indexes. I am currently using PL/SQL Developer a third party tool which is okay for extracting DDL for Non Partitioned tables, but when it comes to getting the DDL for PARTITIONED tables, it doesnt give me the partition information nor the tablespace information. We dont have a license for Toad or any other tools to get the DDL's. I also dont have the export/import privs on the DB. I need a free ware that can give me the DDL for the existing partitioned tables or atleast a query that I can run against the regular DBA views, which can give me the DDL along with Storage clause, the tablespace, indexes, grants & constraints.
    Thanks in Advance
    Chandra

    I also dont have the export/import privs on the DB. I need a
    free ware that can give me the DDL for the existing
    partitioned tables or atleast a query that I can run
    against the regular DBA views, which can give me the
    DDL along with Storage clause, the tablespace,
    indexes, grants & constraints.But you (or the owner or the tables you connect with) should have export/import privs on its on tables (i.e the two tables). So use the User Views instead of DBA Views.
    USER_TABLES, USER_TAB_PARTITIONS etc

  • 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

  • Auto stats gathering for partitioned table

    Hi,
    We are in 10gR2 in sun solaris. We are using auto stats gathering for our DB. Here is my question,
    i know oracle gather statistics of the table, if the table changes more than 10%. How this work out for partitioned table? If the partition table changes more than 10% will last partition analyzed or the full table. We have partitioned based on insertion date.
    Appreciate your responds.
    Regards,
    Satheesh Shanmugam
    http://borndba.com

    I hope it will be only current partition which has teh stale statistics will be gathered the stastics instead of full table.
    Anil Malkai

  • How to use remote directory for external table

    Hi Folks,
    I have 2 Oracle 11GR2 64 bit database installed on Win 2008 server as prod1 and prod2.
    I have one directory created on prod1 server as EXT_TAB_DIR using the path as D:\OrsDWtest_dir .
    I want to use this directory in Prod2 server and use external table using this remote directory.
    I am able to access the Prod1 directory from Prod2 machine and also i have created Network map drive as Z drive pointing to that prod1 D:\OrsDWtest_dir directory. Also i checked read and Write permissions are there . I am able to create the external table but when i try to fetch the data i m getting below error ..
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04040: file IOMM_20121213_060736.csv in EXT_TAB_DIR not found
    now my doubt is this possible ? Can we use remote directory for External table ? or is there is there any alternative way to achieve same ?
    Thanks & Regards,
    Vikash Jain(DBA)

    could you confirm the name and the existence of this file "IOMM_20121213_060736.csv" ?
    same error like:
    http://www.oracle-base.com/articles/9i/external-tables-9i.php
    if the load files have not been saved in the appropriate directory the following result will be displayed.
    SQL> SELECT *
      2  FROM   countries_ext
      3  ORDER BY country_name;
    SELECT *
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04040: file Countries1.txt in EXT_TABLES not found
    ORA-06512: at "SYS.ORACLE_LOADER", line 14
    ORA-06512: at line 1Edited by: Fran on 10-ene-2013 23:32

  • Using a parameter for a table name?

    In SQL Server, can you use a parameter for a table name?  I'm working with Visual C# and want to do something like this:
    SELECT MAX(ItemID) FROM @TableName;
    Can this be done?
    (Basically, I have three separate methods within a class--one for each table I have; and each one will perform the above query but on different table names.  I'd like to see if there is a way that I can have just one method that will allow me to specify
    the table name.)

    As pointed out in other posts, you can. But a more relevant question is whether you should.
    A table in a relational database is supposed to model a unique entity, and each column in the table is supposed to model a unique attribute. This is not always how it is, but it is from this model a relational database is designed.
    From this angle, having a dynamic table name does not really make sense for application code. (Administrative actions is a different story.) Think of it this way: have you ever wanted to make the class name dynamic in C#?
    Admittedly, it is different in .NET, because everything inherits from System.Object, but in a relational database there is no inheritence.
    Anyway, if you are using stored procedures, you should have one stored procedure per table. Physically, in the plan cache, there will be one query plan per table, no matter how you do it.
    If you are submitting SQL statements from your application, it is a different matter. In this case, I find it difficult to object if you have a class that performs generic actions against tables. Then you build the SQL string in the client code.
    However, no matter how you do it, you need to be careful to avoid SQL injection. We had the example:
    DECLARE @TableName nvarchar(50),@sqlCommand nvarchar(max)
      SET @TableName = ' ItemInformation'
      SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + @TableName
    EXEC (@sqlCommand)
    But what if we have:
      SET @TableName = ' sys.objects; SHUTDOWN WITH NOWAIT; --'
    As long as we do it in T-SQL, we can (and we should do!) this to prevent SQL injection:
      SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + quotename(@TableName)
    If you build your SQL strings in C#, you will need to employ other checks. There is only an issue if the user can inject data somewhere, but your generic class will not have knowledge of this, and must assume the worst.
    Erland Sommarskog, SQL Server MVP, [email protected]

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

  • Performance issue when trying to execute DBMS_METADATA.GET_DDL of a table

    Hello.
    I have a database with lots of partitioned tables and indexes and when I try to get the DDL of a partitioned table the query runs for hours and does not end.
    I tried do gather data dictionary statistics but it had no impact on performance.
    Can anybody help me find what's causing this performance problem?
    Information about the enviorment:
    Oracle version:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    DDL query:
    select dbms_metadata.get_ddl('TABLE', 'TABLE1') from dual;
    On the "Top Activity" of the Database Control console, this is the query that's running:
    SELECT /*+all_rows*/ SYS_XMLGEN(VALUE(KU$), XMLFORMAT.createFormat2('TABLE_T', '7')), KU$.OBJ_NUM
    FROM SYS.KU$_PHTABLE_VIEW KU$
    WHERE NOT (BITAND (KU$.PROPERTY,8192)=8192) AND NOT BITAND(KU$.SCHEMA_OBJ.FLAGS,128)!=0 AND KU$.SCHEMA_OBJ.NAME=:NAME1 AND KU$.SCHEMA_OBJ.OWNER_NAME=:SCHEMA2;
    Edited by: Krulikowski on Jan 11, 2013 10:44 AM

    |*563 | INDEX RANGE SCAN | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 564 | TABLE ACCESS CLUSTER | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*565 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 566 | VIEW | | 1 | 86 | | 4 (25)| 00:00:01 |
    | 567 | SORT ORDER BY | | 1 | 64 | | 4 (25)| 00:00:01 |
    | 568 | NESTED LOOPS | | 1 | 64 | | 3 (0)| 00:00:01 |
    | 569 | ID TABLE ACCESS BY INDEX ROW | SUBPARTCOL$ | 1 | 15 | | 2 (0)| 00:00:01 |
    |*570 | INDEX RANGE SCAN | I_SUBPARTCOL$ | 1 | | | 1 (0)| 00:00:01 |
    |*571 | TABLE ACCESS CLUSTER | COL$ | 1 | 49 | | 1 (0)| 00:00:01 |
    |*572 | INDEX UNIQUE SCAN | I_OBJ# | 1 | | | 0 (0)| 00:00:01 |
    | 573 | TABLE ACCESS CLUSTER | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*574 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 575 | TABLE ACCESS CLUSTER | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*576 | INDEX UNIQUE SCAN | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 577 | ROWID TABLE ACCESS BY INDEX | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*578 | INDEX UNIQUE SCAN | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 579 | TABLE ACCESS CLUSTER | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*580 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 581 | NESTED LOOPS | | 1 | 120 | | 5 (0)| 00:00:01 |
    | 582 | X ROWID TABLE ACCESS BY INDE | OBJ$ | 1 | 101 | | 4 (0)| 00:00:01 |
    |*583 | INDEX RANGE SCAN | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 584 | TABLE ACCESS CLUSTER | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*585 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 586 | R TABLE ACCESS CLUSTE | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*587 | INDEX UNIQUE SCAN | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 588 | DEX ROWID TABLE ACCESS BY IN | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*589 | INDEX UNIQUE SCAN | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 590 | TER TABLE ACCESS CLUS | TS$ | 1 | 18 | | 1 (0)| 00:00:01 |
    |*591 | N INDEX UNIQUE SCA | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 592 | STER TABLE ACCESS CLU | TS$ | 1 | 8 | | 1 (0)| 00:00:01 |
    |*593 | AN INDEX UNIQUE SC | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 594 | USTER TABLE ACCESS CL | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*595 | CAN INDEX UNIQUE S | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 596 | LUSTER TABLE ACCESS C | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*597 | SCAN INDEX UNIQUE | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 598 | BY INDEX ROWID TABLE ACCESS | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*599 | SCAN INDEX UNIQUE | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 600 | NESTED LOOPS | | 1 | 447 | | 900 (1)| 00:00:04 |
    |*601 | HASH JOIN | | 1 | 425 | | 899 (1)| 00:00:04 |
    | 602 | NESTED LOOPS | | 1 | 120 | | 5 (0)| 00:00:01 |
    | 603 | BY INDEX ROWID TABLE ACCESS | OBJ$ | 1 | 101 | | 4 (0)| 00:00:01 |
    |*604 | SCAN INDEX RANGE | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 605 | CLUSTER TABLE ACCESS | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*606 | E SCAN INDEX UNIQU | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    |*607 | VIEW | INDPARTV$ | 33387 | 9944K| | 893 (1)| 00:00:04 |
    | 608 | R WINDOW BUFFE | | 33387 | 4336K| | 893 (1)| 00:00:04 |
    | 609 | S BY INDEX ROWID TABLE ACCES | INDPART$ | 33387 | 4336K| | 893 (1)| 00:00:04 |
    | 610 | SCAN INDEX FULL | I_INDPART_BOPART$ | 33387 | | | 103 (1)| 00:00:01 |
    | 611 | LUSTER TABLE ACCESS C | TS$ | 1 | 22 | | 1 (0)| 00:00:01 |
    |*612 | SCAN INDEX UNIQUE | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 613 | VIEW | | 19858 | 40M| | 1471 (1)| 00:00:07 |
    | 614 | SORT ORDER BY | | 19858 | 3956K| 4688K| 1471 (1)| 00:00:07 |
    |*615 | HASH JOIN | | 19858 | 3956K| | 698 (1)| 00:00:03 |
    | 616 | TABLE ACCESS FULL | LOB$ | 1547 | 24752 | | 461 (1)| 00:00:02 |
    |*617 | VIEW | LOBFRAGV$ | 19858 | 3645K| | 236 (1)| 00:00:01 |
    | 618 | WINDOW BUFFER | | 19858 | 1066K| | 236 (1)| 00:00:01 |
    | 619 | INDEX ROWID TABLE ACCESS BY | LOBFRAG$ | 19858 | 1066K| | 236 (1)| 00:00:01 |
    | 620 | INDEX FULL SCAN | I_LOBFRAG_PARENTOBJFRAG$ | 19858 | | | 61 (0)| 00:00:01 |
    | 621 | ER TABLE ACCESS CLUST | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*622 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 623 | NESTED LOOPS | | 1 | 120 | | 5 (0)| 00:00:01 |
    | 624 | NDEX ROWID TABLE ACCESS BY I | OBJ$ | 1 | 101 | | 4 (0)| 00:00:01 |
    |*625 | INDEX RANGE SCAN | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 626 | TER TABLE ACCESS CLUS | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*627 | N INDEX UNIQUE SCA | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 628 | NESTED LOOPS | | 1 | 53 | | 5 (0)| 00:00:01 |
    | 629 | INDEX ROWID TABLE ACCESS BY | OBJ$ | 1 | 34 | | 4 (0)| 00:00:01 |
    |*630 | AN INDEX RANGE SC | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 631 | USTER TABLE ACCESS CL | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*632 | CAN INDEX UNIQUE S | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    |*633 | STER TABLE ACCESS CLU | COL$ | 1 | 49 | | 2 (0)| 00:00:01 |
    |*634 | AN INDEX UNIQUE SC | I_OBJ# | 1 | | | 1 (0)| 00:00:01 |
    | 635 | USTER TABLE ACCESS CL | TAB$ | 1 | 13 | | 2 (0)| 00:00:01 |
    |*636 | CAN INDEX UNIQUE S | I_OBJ# | 1 | | | 1 (0)| 00:00:01 |
    | 637 | Y INDEX ROWID TABLE ACCESS B | COLTYPE$ | 1 | 13 | | 2 (0)| 00:00:01 |
    |*638 | SCAN INDEX UNIQUE | I_COLTYPE2 | 1 | | | 1 (0)| 00:00:01 |
    | 639 | CLUSTER TABLE ACCESS | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*640 | SCAN INDEX UNIQUE | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 641 | BY INDEX ROWID TABLE ACCESS | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*642 | E SCAN INDEX UNIQU | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 643 | S CLUSTER TABLE ACCES | TS$ | 1 | 18 | | 1 (0)| 00:00:01 |
    |*644 | UE SCAN INDEX UNIQ | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 645 | SS CLUSTER TABLE ACCE | TS$ | 1 | 8 | | 1 (0)| 00:00:01 |
    |*646 | QUE SCAN INDEX UNI | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 647 | NESTED LOOPS | | 1 | 55 | | 3 (0)| 00:00:01 |
    | 648 | BY INDEX ROWID TABLE ACCESS | TABPART$ | 1 | 42 | | 2 (0)| 00:00:01 |
    |*649 | E SCAN INDEX UNIQU | I_TABPART_OBJ$ | 1 | | | 1 (0)| 00:00:01 |
    |*650 | CLUSTER TABLE ACCESS | TAB$ | 1 | 13 | | 1 (0)| 00:00:01 |
    |*651 | E SCAN INDEX UNIQU | I_OBJ# | 1 | | | 0 (0)| 00:00:01 |
    |*652 | FILTER | | | | | | |
    | 653 | MERGE JOIN | | 53239 | 2287K| | 1334 (2)| 00:00:06 |
    |*654 | VIEW | TABPARTV$ | 96857 | 3026K| | 872 (2)| 00:00:04 |
    | 655 | WINDOW SORT | | 96857 | 1513K| 2672K| 872 (2)| 00:00:04 |
    | 656 | ULL TABLE ACCESS F | TABPART$ | 96857 | 1513K| | 414 (2)| 00:00:02 |
    |*657 | SORT JOIN | | 273 | 3276 | | 462 (1)| 00:00:02 |
    | 658 | LL TABLE ACCESS FU | NTAB$ | 273 | 3276 | | 461 (1)| 00:00:02 |
    |*659 | FILTER | | | | | | |
    |*660 | FILTERING (UNIQUE) CONNECT BY WITH | | | | | | |
    | 661 | INDEX ROWID TABLE ACCESS BY | NTAB$ | 2 | 16 | | 2 (0)| 00:00:01 |
    |*662 | AN INDEX RANGE SC | I_NTAB1 | 2 | | | 1 (0)| 00:00:01 |
    | 663 | NESTED LOOPS | | 4 | 84 | | 4 (0)| 00:00:01 |
    | 664 | P CONNECT BY PUM | | | | | | |
    | 665 | LUSTER TABLE ACCESS C | NTAB$ | 2 | 16 | | 1 (0)| 00:00:01 |
    |*666 | SCAN INDEX UNIQUE | I_OBJ# | 1 | | | 0 (0)| 00:00:01 |
    |*667 | HASH JOIN | | 1 | 32 | | 5 (20)| 00:00:01 |
    |*668 | TER TABLE ACCESS CLUS | TAB$ | 1 | 13 | | 2 (0)| 00:00:01 |
    |*669 | N INDEX UNIQUE SCA | I_OBJ# | 1 | | | 1 (0)| 00:00:01 |
    |*670 | VIEW | TABPARTV$ | 214 | 4066 | | 2 (0)| 00:00:01 |
    | 671 | WINDOW BUFFER | | 214 | 2140 | | 2 (0)| 00:00:01 |
    |*672 | N INDEX RANGE SCA | I_TABPART_BOPART$ | 214 | 2140 | | 2 (0)| 00:00:01 |
    | 673 | VIEW | | 214 | 1304K| | 1555 (2)| 00:00:07 |
    | 674 | SORT ORDER BY | | 214 | 72546 | | 1555 (2)| 00:00:07 |
    |*675 | HASH JOIN | | 214 | 72546 | | 1554 (2)| 00:00:07 |
    | 676 | TABLE ACCESS FULL | USER$ | 184 | 3496 | | 4 (0)| 00:00:01 |
    | 677 | NESTED LOOPS | | | | | | |
    | 678 | NESTED LOOPS | | 214 | 68480 | | 1549 (2)| 00:00:07 |
    |*679 | HASH JOIN | | 214 | 46866 | | 907 (2)| 00:00:04 |
    |*680 | HASH JOIN | | 214 | 42800 | | 34 (3)| 00:00:01 |
    | 681 | TABLE ACCESS FULL | TS$ | 138 | 3036 | | 26 (0)| 00:00:01 |
    | 682 | NDEX ROWID TABLE ACCESS BY I | TABPART$ | 214 | 38092 | | 7 (0)| 00:00:01 |
    |*683 | INDEX RANGE SCAN | I_TABPART_BOPART$ | 214 | | | 2 (0)| 00:00:01 |
    | 684 | VIEW | TABPARTV$ | 96857 | 1797K| | 872 (2)| 00:00:04 |
    | 685 | WINDOW SORT | | 96857 | 1513K| 2672K| 872 (2)| 00:00:04 |
    | 686 | L TABLE ACCESS FUL | TABPART$ | 96857 | 1513K| | 414 (2)| 00:00:02 |
    |*687 | INDEX RANGE SCAN | I_OBJ1 | 1 | | | 2 (0)| 00:00:01 |
    | 688 | X ROWID TABLE ACCESS BY INDE | OBJ$ | 1 | 101 | | 3 (0)| 00:00:01 |
    | 689 | TABLE ACCESS CLUSTER | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*690 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 691 | TABLE ACCESS CLUSTER | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*692 | INDEX UNIQUE SCAN | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 693 | R TABLE ACCESS CLUSTE | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*694 | INDEX UNIQUE SCAN | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 695 | DEX ROWID TABLE ACCESS BY IN | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*696 | INDEX UNIQUE SCAN | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 697 | TER TABLE ACCESS CLUS | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*698 | N INDEX UNIQUE SCA | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 699 | NESTED LOOPS | | 1 | 120 | | 5 (0)| 00:00:01 |
    | 700 | INDEX ROWID TABLE ACCESS BY | OBJ$ | 1 | 101 | | 4 (0)| 00:00:01 |
    |*701 | N INDEX RANGE SCA | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 702 | STER TABLE ACCESS CLU | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*703 | AN INDEX UNIQUE SC | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 704 | USTER TABLE ACCESS CL | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*705 | CAN INDEX UNIQUE S | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 706 | Y INDEX ROWID TABLE ACCESS B | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*707 | SCAN INDEX UNIQUE | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 708 | CLUSTER TABLE ACCESS | TS$ | 1 | 18 | | 1 (0)| 00:00:01 |
    |*709 | SCAN INDEX UNIQUE | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 710 | CLUSTER TABLE ACCESS | TS$ | 1 | 8 | | 1 (0)| 00:00:01 |
    |*711 | E SCAN INDEX UNIQU | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 712 | S CLUSTER TABLE ACCES | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*713 | UE SCAN INDEX UNIQ | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 714 | SS CLUSTER TABLE ACCE | SEG$ | 1 | 70 | | 3 (0)| 00:00:01 |
    |*715 | QUE SCAN INDEX UNI | I_FILE#_BLOCK# | 1 | | | 2 (0)| 00:00:01 |
    | 716 | ESS BY INDEX ROWID TABLE ACC | DEFERRED_STG$ | 1 | 28 | | 2 (0)| 00:00:01 |
    |*717 | IQUE SCAN INDEX UN | I_DEFERRED_STG1 | 1 | | | 1 (0)| 00:00:01 |
    | 718 | S NESTED LOOP | | 1 | 421 | | 2864 (1)| 00:00:13 |
    | 719 | PS NESTED LOO | | 1 | 402 | | 2863 (1)| 00:00:13 |
    | 720 | N MERGE JOI | | 1 | 380 | | 2862 (1)| 00:00:13 |
    |*721 | VIEW | INDSUBPARTV$ | 203K| 54M| | 2857 (1)| 00:00:13 |
    | 722 | BUFFER WINDOW | | 203K| 13M| | 2857 (1)| 00:00:13 |
    | 723 | ACCESS BY INDEX ROWID TABLE | INDSUBPART$ | 203K| 13M| | 2857 (1)| 00:00:13 |
    | 724 | FULL SCAN INDEX | I_INDSUBPART_POBJSUBPART$ | 203K| | | 517 (1)| 00:00:03 |
    |*725 | N SORT JOI | | 1 | 101 | | 5 (20)| 00:00:01 |
    | 726 | CCESS BY INDEX ROWID TABLE A | OBJ$ | 1 | 101 | | 4 (0)| 00:00:01 |
    |*727 | RANGE SCAN INDEX | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |
    | 728 | ESS CLUSTER TABLE ACC | TS$ | 1 | 22 | | 1 (0)| 00:00:01 |
    |*729 | IQUE SCAN INDEX UN | I_TS# | 1 | | | 0 (0)| 00:00:01 |
    | 730 | SS CLUSTER TABLE ACCE | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*731 | QUE SCAN INDEX UNI | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 732 | VIEW | | 3220 | 6653K| | 252 (2)| 00:00:02 |
    | 733 | SORT ORDER BY | | 3220 | 679K| | 252 (2)| 00:00:02 |
    |*734 | HASH JOIN | | 3220 | 679K| | 251 (1)| 00:00:02 |
    | 735 | NESTED LOOPS | | | | | | |
    | 736 | NESTED LOOPS | | 12 | 336 | | 14 (0)| 00:00:01 |
    | 737 | FULL TABLE ACCESS | LOBCOMPPART$ | 12 | 144 | | 2 (0)| 00:00:01 |
    |*738 | SCAN INDEX UNIQUE | I_LOB2 | 1 | | | 0 (0)| 00:00:01 |
    | 739 | BY INDEX ROWID TABLE ACCESS | LOB$ | 1 | 16 | | 1 (0)| 00:00:01 |
    |*740 | VIEW | LOBFRAGV$ | 19858 | 3645K| | 236 (1)| 00:00:01 |
    | 741 | WINDOW BUFFER | | 19858 | 1066K| | 236 (1)| 00:00:01 |
    | 742 | BY INDEX ROWID TABLE ACCESS | LOBFRAG$ | 19858 | 1066K| | 236 (1)| 00:00:01 |
    | 743 | SCAN INDEX FULL | I_LOBFRAG_PARENTOBJFRAG$ | 19858 | | | 61 (0)| 00:00:01 |
    | 744 | Y INDEX ROWID TABLE ACCESS B | TABSUBPART$ | 1 | 111 | | 3 (0)| 00:00:01 |
    |*745 | SCAN INDEX UNIQUE | I_TABSUBPART$_OBJ$ | 1 | | | 2 (0)| 00:00:01 |
    | 746 | VIEW | | 418K| 2477M| | 38130 (1)| 00:02:41 |
    | 747 | SORT ORDER BY | | 418K| 177M| 192M| 38130 (1)| 00:02:41 |
    |*748 | HASH JOIN | | 418K| 177M| | 3590 (3)| 00:00:16 |
    | 749 | TABLE ACCESS FULL | USER$ | 184 | 3496 | | 4 (0)| 00:00:01 |
    |*750 | HASH JOIN | | 418K| 170M| | 3582 (2)| 00:00:16 |
    | 751 | L TABLE ACCESS FUL | TS$ | 138 | 3036 | | 26 (0)| 00:00:01 |
    |*752 | HASH JOIN | | 418K| 161M| | 3552 (2)| 00:00:15 |
    | 753 | VIEW | TABSUBPARTV$ | 30 | 9120 | | 4 (0)| 00:00:01 |
    | 754 | WINDOW BUFFER | | 30 | 3750 | | 4 (0)| 00:00:01 |
    | 755 | BY INDEX ROWID TABLE ACCESS | TABSUBPART$ | 30 | 3750 | | 4 (0)| 00:00:01 |
    |*756 | SCAN INDEX RANGE | I_TABSUBPART_POBJSUBPART$ | 30 | | | 3 (0)| 00:00:01 |
    | 757 | LL TABLE ACCESS FU | OBJ$ | 825K| 79M| | 3539 (2)| 00:00:15 |
    | 758 | NDEX ROWID TABLE ACCESS BY I | LOB$ | 1 | 10 | | 2 (0)| 00:00:01 |
    |*759 | N INDEX UNIQUE SCA | I_LOB2 | 1 | | | 1 (0)| 00:00:01 |
    | 760 | STER TABLE ACCESS CLU | USER$ | 1 | 19 | | 1 (0)| 00:00:01 |
    |*761 | AN INDEX UNIQUE SC | I_USER# | 1 | | | 0 (0)| 00:00:01 |
    | 762 | NESTED LOOPS | | 1 | 120 | | 5 (0)| 00:00:01 |
    | 763 | INDEX ROWID TABLE ACCESS BY | OBJ$ | 1 | 101 | | 4 (0)| 00:00:01 |
    |*764 | AN INDEX RANGE SC | I_OBJ1 | 1 | | | 3 (0)| 00:00:01 |

  • Dbms_metadata.GET_DDL for all procedures for a schema

    I am trying to capture all the procedure DDLs for schema CUSTOM
    I am using 11g on Linux.
    I run this command...
    SELECT dbms_metadata.GET_DDL('PROCEDURE',NULL,'CUSTOM') FROM DUAL;
    And get this error:
    ORA-31600: invalid input value NULL for parameter VALUE in function SET_FILTER
    ORA-06512: at "SYS.DBMS_METADATA", line 4018
    ORA-06512: at "SYS.DBMS_METADATA", line 5843
    ORA-06512: at line 1
    Thanks in advance.

    user13716252 wrote:
    I am trying to capture all the procedure DDLs for schema CUSTOM
    I am using 11g on Linux.
    I run this command...
    SELECT dbms_metadata.GET_DDL('PROCEDURE',NULL,'CUSTOM') FROM DUAL;
    And get this error:
    ORA-31600: invalid input value NULL for parameter VALUE in function SET_FILTER
    ORA-06512: at "SYS.DBMS_METADATA", line 4018
    ORA-06512: at "SYS.DBMS_METADATA", line 5843
    ORA-06512: at line 1
    Thanks in advance.specify actual procedure name; not NULL

  • Error while viewing Scripts using dbms_metadata.get_ddl

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

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

  • Partition pruning not working for partitioned table joins

    Hi,
    We are joining  4 partitioned tables on partition column & other key columns. And we are filtering the driving table on partition key. But explain plan is showing that all tables except the driving table are not partition pruning and scanning all partitions.Is there any limitation that filter condition cannot be dynamic?
    Thanks a lot in advance.
    Here are the details...
    SELECT a.pay_prd_id,
                  a.a_id,
                  a.a_evnt_no
      FROM b,
                c,
                a,
                d
    WHERE  (    a.pay_prd_id = b.pay_prd_id ---partition range all
                AND a.a_evnt_no  = b.b_evnt_no
                AND a.a_id       = b.b_id
       AND (    a.pay_prd_id = c.pay_prd_id---partition range all
            AND a.a_evnt_no  = c.c_evnt_no
            AND a.a_id       = c.c_id
       AND (    a.pay_prd_id = d.pay_prd_id---partition range all
            AND a.a_evnt_no  = d.d_evnt_no
            AND a.a_id       = d.d_id
       AND (a.pay_prd_id =  ---partition range single
               CASE '201202'
                  WHEN 'YYYYMM'
                     THEN (SELECT min(pay_prd_id)
                                      FROM pay_prd
                                     WHERE pay_prd_stat_cd = 2)
                  ELSE TO_NUMBER ('201202', '999999')
               END
    DDLs.
    create table pay_prd
    pay_prd_id number(6),
    pay_prd_stat_cd integer,
    pay_prd_stat_desc varchar2(20),
    a_last_upd_dt DATE
    insert into pay_prd
    select 201202,2,'OPEN',sysdate from dual
    union all
    select 201201,1,'CLOSE',sysdate from dual
    union all
    select 201112,1,'CLOSE',sysdate from dual
    union all
    select 201111,1,'CLOSE',sysdate from dual
    union all
    select 201110,1,'CLOSE',sysdate from dual
    union all
    select 201109,1,'CLOSE',sysdate from dual
    CREATE TABLE A
    (PAY_PRD_ID    NUMBER(6) NOT NULL,
    A_ID        NUMBER(9) NOT NULL,
    A_EVNT_NO    NUMBER(3) NOT NULL,
    A_DAYS        NUMBER(3),
    A_LAST_UPD_DT    DATE
    PARTITION BY RANGE (PAY_PRD_ID)
    INTERVAL( 1)
      PARTITION A_0001 VALUES LESS THAN (201504)
    ENABLE ROW MOVEMENT;
    ALTER TABLE A ADD CONSTRAINT A_PK PRIMARY KEY (PAY_PRD_ID,A_ID,A_EVNT_NO) USING INDEX LOCAL;
    insert into a
    select 201202,1111,1,65,sysdate from dual
    union all
    select 201202,1111,2,75,sysdate from dual
    union all
    select 201202,1111,3,85,sysdate from dual
    union all
    select 201202,1111,4,95,sysdate from dual
    CREATE TABLE B
    (PAY_PRD_ID    NUMBER(6) NOT NULL,
    B_ID        NUMBER(9) NOT NULL,
    B_EVNT_NO    NUMBER(3) NOT NULL,
    B_DAYS        NUMBER(3),
    B_LAST_UPD_DT    DATE
    PARTITION BY RANGE (PAY_PRD_ID)
    INTERVAL( 1)
      PARTITION B_0001 VALUES LESS THAN (201504)
    ENABLE ROW MOVEMENT;
    ALTER TABLE B ADD CONSTRAINT B_PK PRIMARY KEY (PAY_PRD_ID,B_ID,B_EVNT_NO) USING INDEX LOCAL;
    insert into b
    select 201202,1111,1,15,sysdate from dual
    union all
    select 201202,1111,2,25,sysdate from dual
    union all
    select 201202,1111,3,35,sysdate from dual
    union all
    select 201202,1111,4,45,sysdate from dual
    CREATE TABLE C
    (PAY_PRD_ID    NUMBER(6) NOT NULL,
    C_ID        NUMBER(9) NOT NULL,
    C_EVNT_NO    NUMBER(3) NOT NULL,
    C_DAYS        NUMBER(3),
    C_LAST_UPD_DT    DATE
    PARTITION BY RANGE (PAY_PRD_ID)
    INTERVAL( 1)
      PARTITION C_0001 VALUES LESS THAN (201504)
    ENABLE ROW MOVEMENT;
    ALTER TABLE C ADD CONSTRAINT C_PK PRIMARY KEY (PAY_PRD_ID,C_ID,C_EVNT_NO) USING INDEX LOCAL;
    insert into c
    select 201202,1111,1,33,sysdate from dual
    union all
    select 201202,1111,2,44,sysdate from dual
    union all
    select 201202,1111,3,55,sysdate from dual
    union all
    select 201202,1111,4,66,sysdate from dual
    CREATE TABLE D
    (PAY_PRD_ID    NUMBER(6) NOT NULL,
    D_ID        NUMBER(9) NOT NULL,
    D_EVNT_NO    NUMBER(3) NOT NULL,
    D_DAYS        NUMBER(3),
    D_LAST_UPD_DT    DATE
    PARTITION BY RANGE (PAY_PRD_ID)
    INTERVAL( 1)
      PARTITION D_0001 VALUES LESS THAN (201504)
    ENABLE ROW MOVEMENT;
    ALTER TABLE D ADD CONSTRAINT D_PK PRIMARY KEY (PAY_PRD_ID,D_ID,D_EVNT_NO) USING INDEX LOCAL;
    insert into c
    select 201202,1111,1,33,sysdate from dual
    union all
    select 201202,1111,2,44,sysdate from dual
    union all
    select 201202,1111,3,55,sysdate from dual
    union all
    select 201202,1111,4,66,sysdate from dual

    Below query generated from Business Objects and submitted to Database (the case statement is generated by BO). Cant we use Case/Subquery/Decode etc for the partitioned column? We are assuming that  the case causing the issue to not to dynamic partition elimination on the other joined partitioned tables (TAB_B_RPT, TAB_C_RPT).
    SELECT TAB_D_RPT.acvy_amt,
           TAB_A_RPT.itnt_typ_desc,
           TAB_A_RPT.ls_typ_desc,
           TAB_A_RPT.evnt_no,
           TAB_C_RPT.pay_prd_id,
           TAB_B_RPT.id,
           TAB_A_RPT.to_mdfy,
           TAB_A_RPT.stat_desc
      FROM TAB_D_RPT,
           TAB_C_RPT fee_rpt,
           TAB_C_RPT,
           TAB_A_RPT,
           TAB_B_RPT
    WHERE (TAB_B_RPT.id = TAB_A_RPT.id)
       AND (    TAB_A_RPT.pay_prd_id = TAB_D_RPT.pay_prd_id -- expecting Partition Range Single, but doing Partition Range ALL
            AND TAB_A_RPT.evnt_no    = TAB_D_RPT.evnt_no
            AND TAB_A_RPT.id         = TAB_D_RPT.id
       AND (    TAB_A_RPT.pay_prd_id = TAB_C_RPT.pay_prd_id -- expecting Partition Range Single, but doing Partition Range ALL
            AND TAB_A_RPT.evnt_no    = TAB_C_RPT.evnt_no
            AND TAB_A_RPT.id         = TAB_C_RPT.id
       AND (    TAB_A_RPT.pay_prd_id = fee_rpt.pay_prd_id -- expecting Partition Range Single
            AND TAB_A_RPT.evnt_no    = fee_rpt.evnt_no
            AND TAB_A_RPT.id         = fee_rpt.id
       AND (TAB_A_RPT.rwnd_ind = 'N')
       AND (TAB_A_RPT.pay_prd_id =
               CASE '201202'
                  WHEN 'YYYYMM'
                     THEN (SELECT DISTINCT pay_prd.pay_prd_id
                                      FROM pay_prd
                                     WHERE pay_prd.stat_cd = 2)
                  ELSE TO_NUMBER ('201202', '999999')
               END
    And its explain plan is...
    Plan
    SELECT STATEMENT ALL_ROWS Cost: 79 K Bytes: 641 M Cardinality: 3 M
    18 HASH JOIN Cost: 79 K Bytes: 641 M Cardinality: 3 M
    3 PART JOIN FILTER CREATE SYS.:BF0000 Cost: 7 K Bytes: 72 M Cardinality: 3 M
    2 PARTITION RANGE ALL Cost: 7 K Bytes: 72 M Cardinality: 3 M Partition #: 3 Partitions accessed #1 - #1048575
    1 TABLE ACCESS FULL TABLE TAB_D_RPT Cost: 7 K Bytes: 72 M Cardinality: 3 M Partition #: 3 Partitions accessed #1 - #1048575
    17 HASH JOIN Cost: 57 K Bytes: 182 M Cardinality: 874 K
    14 PART JOIN FILTER CREATE SYS.:BF0001 Cost: 38 K Bytes: 87 M Cardinality: 914 K
    13 HASH JOIN Cost: 38 K Bytes: 87 M Cardinality: 914 K
    6 PART JOIN FILTER CREATE SYS.:BF0002 Cost: 8 K Bytes: 17 M Cardinality: 939 K
    5 PARTITION RANGE ALL Cost: 8 K Bytes: 17 M Cardinality: 939 K Partition #: 9 Partitions accessed #1 - #1048575
    4 TABLE ACCESS FULL TABLE TAB_C_RPT Cost: 8 K Bytes: 17 M Cardinality: 939 K Partition #: 9 Partitions accessed #1 - #1048575
    12 HASH JOIN Cost: 24 K Bytes: 74 M Cardinality: 957 K
    7 INDEX FAST FULL SCAN INDEX (UNIQUE) TAB_B_RPT_PK Cost: 675 Bytes: 10 M Cardinality: 941 K
    11 PARTITION RANGE SINGLE Cost: 18 K Bytes: 65 M Cardinality: 970 K Partition #: 13 Partitions accessed #KEY(AP)
    10 TABLE ACCESS FULL TABLE TAB_A_RPT Cost: 18 K Bytes: 65 M Cardinality: 970 K Partition #: 13 Partitions accessed #KEY(AP)
    9 HASH UNIQUE Cost: 4 Bytes: 14 Cardinality: 2
    8 TABLE ACCESS FULL TABLE PAY_PRD Cost: 3 Bytes: 14 Cardinality: 2
    16 PARTITION RANGE JOIN-FILTER Cost: 8 K Bytes: 106 M Cardinality: 939 K Partition #: 17 Partitions accessed #:BF0001
    15 TABLE ACCESS FULL TABLE TAB_C_RPT Cost: 8 K Bytes: 106 M Cardinality: 939 K Partition #: 17 Partitions accessed #:BF0001
    Thanks Again.

Maybe you are looking for