EXECUTE IMMEDIATE AND BULK INSERT

Hi,
I have a code
EXECUTE IMMEDIATE 'INSERT INTO PRC_ExcelDocumentStore_T(object_id,seg_index,segment,value,seg_length) VALUES (:object_id,:seg_index,:segment,:value,:seg_length)'
USING SELF.object_id,p_index,p_segment,p_value,lengthc(v_value)+2;
But due to some performance issue ,I can't use like this.Can you please suggest can i use Bulk Inserts instead of 'EXECUTE IMMEDIATE' statement.
If I can do,please give me an example.
Thanks in advance

user10619377 wrote:
Hi,
I have a code
EXECUTE IMMEDIATE 'INSERT INTO PRC_ExcelDocumentStore_T(object_id,seg_index,segment,value,seg_length) VALUES (:object_id,:seg_index,:segment,:value,:seg_length)'
USING SELF.object_id,p_index,p_segment,p_value,lengthc(v_value)+2;
But due to some performance issue ,I can't use like this.Can you please suggest can i use Bulk Inserts instead of 'EXECUTE IMMEDIATE' statement.
If I can do,please give me an example.How can we give example when we don't know what you have now or what exactly needs to be done.?

Similar Messages

  • Blob truncated with DbFactory and Bulk insert

    Hi,
    My platform is a Microsoft Windows Server 2003 R2 Server 5.2 Service Pack 2 (64-bit) with an Oracle Database 11g 11.1.0.6.0.
    I use the client Oracle 11g ODAC 11.1.0.7.20.
    Some strange behavior appends when used DbFactory and bulk command with Blob column and parameter with a size larger than 65536bytes. Let me explain.
    First i create a dummy table in my schema :
    create table dummy (a number, b blob)To use bulk insert we can use the code A with oracle object (succes to execute) :
    byte[] b1 = new byte[65530];
    byte[] b2 = new byte[65540];
    Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection("User Id=login;Password=pws;Data Source=orcl;");
    OracleCommand cmd = new OracleCommand("insert into dummy values (:p1,:p2)", conn);
    cmd.ArrayBindCount = 2;
    OracleParameter p1 = new OracleParameter("p1", OracleDbType.Int32);
    p1.Direction = ParameterDirection.Input;
    p1.Value = new int[] { 1, 2 };
    cmd.Parameters.Add(p1);
    OracleParameter p2 = new OracleParameter("p2", OracleDbType.Blob);
    p2.Direction = ParameterDirection.Input;
    p2.Value = new byte[][] { b1, b2 };
    cmd.Parameters.Add(p2);
    conn.Open(); cmd.ExecuteNonQuery(); conn.Close();We can write the same thing with an abstract level when used the DbProviderFactories (code B) :
    var factory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
    DbConnection conn = factory.CreateConnection();
    conn.ConnectionString = "User Id=login;Password=pws;Data Source=orcl;";
    DbCommand cmd = conn.CreateCommand();
    cmd.CommandText = "insert into dummy values (:p1,:p2)";
    ((OracleCommand)cmd).ArrayBindCount = 2;
    DbParameter param = cmd.CreateParameter();
    param.ParameterName = "p1";
    param.DbType = DbType.Int32;
    param.Value = new int[] { 3, 4 };
    cmd.Parameters.Add(param);
    DbParameter param2 = cmd.CreateParameter();
    param2.ParameterName = "p2";
    param2.DbType = DbType.Binary;
    param2.Value = new byte[][] { b1, b2 };
    cmd.Parameters.Add(param2);
    conn.Open(); cmd.ExecuteNonQuery(); conn.Close();But this second code doesn't work, the second array of byte is truncated to 4byte. It seems to be an int16 overtaking.
    When used a DbTYpe.Binary, oracle use an OracleDbType.Raw for mapping and not an OracleDbType.Blob, so the problem seems to be with raw type, BUT if we use the same code without bulk insert, it's worked !!! The problem is somewhere else...
    Why used an DbConnection ? To be able to switch easy to an another database type.
    So why used "((OracleCommand)cmd).ArrayBindCount" ? To be able to used specific functionality of each database.
    I can fix the issue when casting DbParameter as OracleParameter and fix the OracleDbType to Blob, but why second code does not working with bulk and working with simple query ?

    BCP and BULK INSERT does not work the way you expect them do. What they do is that they consume fields in a round-robin fashion. That is, they first looks for data for the first field, then for the second field and so on.
    So in your case, they will first read one byte, then 20 bytes etc until they have read the two bytes for field 122. At this point they will consume bytes until they have found a sequence of carriage return and line feed.
    You say that some records in the file are incomplete. Say that there are only 60 fields in this file. Field 61 is four bytes. BCP and BULK INSERT will now read data for field 61 as CR+LF+the first two bytes in the next row. CR+LF has no special meaning,
    but they are just data at this point.
    You will have to write a program to parse the file, or use SSIS. But BCP and BULK INSERT are not your friends in this case.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Execute immediate and dynamic sql

    Dear all;
    Just curious....Why do developers still use dynamic sql..and execute immediate, because I always thought dynamic sql were bads and the use of execute immediate as well...
    or am I missing something...

    There are no 'bad' things and 'good' things.
    There are 'correctly used' and 'incorrectly used' features.
    It depends what you want to do.
    One simple example: Oracle 11.2 - you write a package that fetches data from range interval partitioned table (a new partition is created automatically every day when new key values are inserted). If you use static SQL then whenever Oracle creates a new partition then your package gets invalidated and has to be compiled. If your package is heavily used (by many sessions running in parallel) then you may get this:
    ORA-04068: existing state of packages has been discarded
    ORA-04061: existing state of package body "PACKAGE.XXXXX" has been invalidated
    ORA-06508: PL/SQL: could not find program unit being called: "PACKAGE.XXXXX" Nice, isn't it?
    You can avoid this kind of problems by simply using dynamic SQL. You break dependency with the table and your package is not invalidated when new partition is created.

  • How to get current month from filename and bulk insert from text file into table?

    I set up some dynamic SQL to help my bulk copy data from a text file to a table.  This works fine for files that come in every day; I get the previous day’s data, based on the file name that’s placed
    in the folder.  That’s why I’m using the ‘-1’.  The dates will look like this: '20140131', so I'm using type 112.
    declare @fullpath1 varchar(1000)
    select @fullpath1 = '''\\system.local\ms\london\FTP\' + convert(varchar, getdate()-1, 112) + '_INDEXPRICES_EOM.SPC'''
    declare @cmd1 nvarchar(1000)
    print (@cmd1)
    select @cmd1 = 'bulk insert [dbo].[SB_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
    print(@cmd1)
    exec (@cmd1)
    I think the syntax will be somewhat similar to this:
    YEAR(date_column)=YEAR(getdate()) AND MONTH(date_column)=MONTH(getdate())
    I’m not totally sure how to incorporate that into my current syntax.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    I tried a couple versions of this.
    Declare @StartDate Date, @EndDate Date
    Select @StartDate = convert(varchar, getdate()-28, 112), @EndDate = convert(varchar, getdate()-1, 112)
    BEGIN
    declare @fullpath1 varchar(1000)
    select @fullpath1 = '''\\ms\london\FTP\' + ''' between ''' + Convert(Varchar(10), @StartDate, 101) + ''' and ''' + Convert(Varchar(10), @EndDate, 101) + '''_SP.SPC'''
    declare @cmd1 nvarchar(1000)
    print (@cmd1)
    select @cmd1 = 'bulk insert [dbo].[SPBMI_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
    print(@cmd1)
    exec (@cmd1)
    END
    Here’s the string:
    bulk insert [dbo].[SPBMI_Monthly] from '\\ms\london\FTP\' between '02/03/2014' and '03/02/2014'_SP.SPC' with (FIELDTERMINATOR = '\t', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR='0x0a')
    The error message I keep getting is:
    Msg 156, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'between'.
    Msg 319, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
    I feel like I’m already pushing this thing to the limit. 
    Maybe this last part isn’t possible.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • Getting random LCK_M_SCH_M on convert and bulk insert task

    I starting getting random LCK_M_SCH_M locks with huge wait time, which hung my etl proccess.
    The ssis package runs like this:
    I have 4 containers that run in parallel and do the same thing:
    -Convert a tab delimited file from unicode->utf8
    -Truncate the table (within a foreach loop)
    -Bulk insert the data
    Also transactionoption is set to NotSupported.
    What could be causing the lock?
    All foreach loops do not overlap ragarding tables/files.
    Do they contest somehow?
    Elias

    The truncate table command imposes the schema lock so you will have to not to run in parallel this task
    Arthur
    MyBlog
    Twitter

  • Help with EXECUTE IMMEDIATE and DROP

    Hi all,
    we are trying to create a procedure to do the following:
    * We have in the database some tables named like C$_XXXXXXXXX
    * We want to drop some of these tables that have a common prefix (f.e C$_1203101)
    DECLARE
    v_sql VARCHAR2(300);
    BEGIN
    SELECT 'DROP TABLE ODISTAG.'|| TABLE_NAME ||';' INTO v_sql FROM USER_TABLES WHERE TABLE_NAME LIKE 'C$_1203101%';
    EXECUTE IMMEDIATE v_sql;
    END;
    But we get this error:
    Error report:
    ORA-00911: invalid character
    ORA-06512: at line 5
    00911. 00000 - "invalid character"
    *Cause:    identifiers may not start with any ASCII character other than
    letters and numbers. $#_ are also allowed after the first
    character. Identifiers enclosed by doublequotes may contain
    any character other than a doublequote. Alternative quotes
    (q'#...#') cannot use spaces, tabs, or carriage returns as
    delimiters. For all other contexts, consult the SQL Language
    Reference Manual.
    *Action:
    Any help on that please?
    Thanks!

    This will not work if you fetch more than one row..instead you can do this..
    DECLARE
         v_sql VARCHAR2(30000);
    BEGIN
         for c2 in (
                        SELECT 'DROP TABLE ODISTAG.'|| TABLE_NAME drp
                        FROM USER_TABLES WHERE TABLE_NAME LIKE 'C$_1203101%'
         loop
              v_Sql := c2.drp;
              EXECUTE IMMEDIATE v_sql;
         end loop;
    END;

  • PL/SQL Proc, execute immediate and materialized view 9.2.0.6

    Hello,
    Environement description: Sun Solaris 8 , Oracle database 9.2.0.6
    I've a problem trying to execute this PL/SQL Procedure:
    I'm loged in with PMU user
    CREATE OR REPLACE PROCEDURE PMU.PROC_TEST_PMU_C035 (part_arrete in integer, part_session in integer) AS
    lv_p_arrete number     := part_arrete;
    lv_p_session number     := part_session;
    lv_stmt     varchar2(31000);
    BEGIN
    lv_stmt := ' ';
    lv_stmt := lv_stmt || 'CREATE MATERIALIZED VIEW 'PMU''.''TEST_PMU_C035'' ';
    lv_stmt := lv_stmt || 'TABLESPACE PMU_8M_DATA ';
    lv_stmt := lv_stmt || 'BUILD IMMEDIATE ';
    lv_stmt := lv_stmt || 'REFRESH COMPLETE AS ';
    lv_stmt := lv_stmt || 'SELECT * FROM ACTION ';
    lv_stmt := lv_stmt || 'WHERE LIBELLE IN ( ''SOCIETE 1'', ''SOCIETE 2'', ''SOCIETE 3'' ) ;';
    dbms_output.put_line ( lv_stmt) ;
    execute immediate ( lv_stmt);
    END;
    When I comment the line : execute immediate ( lv_stmt); It works fine and my statement appear on the screen:
    CREATE MATERIALIZED VIEW PMU.TEST_PMU_C035 TABLESPACE PMU_8M_DATA BUILD
    IMMEDIATE REFRESH COMPLETE AS SELECT LIBELLE FROM ACTION WHERE LIBELLE IN (
    'SOCIETE1', 'SOCIETE2', 'SOCIETE3' ) ;
    When I execute manually this query it works.
    But when I try to do the execute immediate, it gives me this error:
    BEGIN "PMU"."PROC_TEST_PMU_C035" ( 13, 14); END;
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "PMU.PROC_TEST_PMU_C035", line 15
    ORA-06512: at line 1
    Action Table has this description and datas:
    SQL> desc action
    Name Null? Type
    ISIN NOT NULL VARCHAR2(20)
    LIBELLE VARCHAR2(100)
    SQL>
    ISIN LIBELLE
    FR1 SOCIETE 1
    FR2 SOCIETE 2
    FR3 SOCIETE 3
    FR4 SOCIETE 4
    FR5 SOCIETE 5
    FR6 SOCIETE 6
    FR7 SOCIETE 7
    FR8 SOCIETE 8
    FR9 SOCIETE 9
    FR10 SOCIETE 10
    FR11 SOCIETE 11
    This is a sample description of my probleme because the real case is on multiple partition tables with million rows, but the problem is the same with this sample.
    My question is why it doesn't work ? Could anybody help me ?
    Thanks In advance.
    Loic

    Yes but you did not show where you want the parametersOK this is my Original Query :
    CREATE OR REPLACE PROCEDURE "PMU"."PROC_TEST_PMU_C035" (part_arrete in integer, part_session in integer)AS
    lv_p_arrete integer := part_arrete;
    lv_p_session integer := part_session;
    lv_stmt varchar2(31000);
    BEGIN
    lv_stmt := 'CREATE OR REPLACE MATERIALIZED VIEW PMU.TEST_PMU_C035 ';
    lv_stmt := lv_stmt || ' TABLESPACE PMU_8M_DATA ';
    lv_stmt := lv_stmt || ' BUILD IMMEDIATE ';
    lv_stmt := lv_stmt || ' REFRESH COMPLETE AS ';
    lv_stmt := lv_stmt || ' select CD_SOCIETE, MONTANT, MOIS, TYPEDET, LIEUCONS, DETPEA, PERSPHYS, SECTDET, PAYSDET, ZONEDET, CSPDET, AGEDET, TRMONT, NATINSFI, MATURITE, MONNAIE, DEVISEISO, SECTEMT, PAYSEMT, ZONEEMT, ENCRSDEB, NBCPTIT, TYPEFLUX, CONTRAT, CODISIN, LIBELTIT, SEUILDET, PAYSCTP, NBTIT, SEUILA1, SEUILA2, SEUILM1, SEUILM2, SEUILB1, SEUILB2, SEUILQ1, SEUILQ2, TXEVOL, NBCPTITPEA, NBCPTITPPP, ';
    lv_stmt := lv_stmt || ' NO_PCI || ''-'' || SECTDET || ''-'' || ZONEDET || ''-'' || MONNAIE || ''-'' || SECTEMT || ''-'' || DETPEA || ''-'' || PERSPHYS || ''-'' || (CASE WHEN TYPEDET IN (''DCL'', ''DCG'') THEN ''DCL'' ';
    lv_stmt := lv_stmt || ' ELSE NVL(TYPEDET,'''') ';
    lv_stmt := lv_stmt || ' END ) || ''-'' || (CASE WHEN NATINSFI in (''OBL'', ''EMT'', ''BTR'', ''CDD'', ''CDE'', ''CPP'', ''BTS'', ''MIB'') THEN ''OBL'' ';
    lv_stmt := lv_stmt || ' ELSE NVL(NATINSFI,'''') ';
    lv_stmt := lv_stmt || ' END) || ''-'' ||(CASE WHEN MATURITE IN (''A0'', ''A1'') THEN ''AC'' ELSE NVL(MATURITE,'''') END) || ''-'' ||(CASE WHEN PAYSEMT IN (''FR'',''MC'') THEN ''F1'' ';
    lv_stmt := lv_stmt || ' WHEN PAYSEMT IN (''DE'',''AT'',''BE'',''ES'',''FI'',''GR'',''IE'',''IT'',''LU'',''NL'',''PT'',''SI'', ''4F'') THEN ''ZE'' ';
    lv_stmt := lv_stmt || ' WHEN PAYSEMT IN (''BG'',''CY'',''DK'',''EE'',''HU'',''LV'',''LT'',''MT'',''PL'',''RO'',''GB'',''SK'',''SE'',''CZ'', ''4C'', ''4D'', ''4H'', ''4E'', ''4Z'', ''JE'') THEN ''ZU'' ';
    lv_stmt := lv_stmt || ' ELSE ''ZR''';
    lv_stmt := lv_stmt || ' END ) AS CLE';
    lv_stmt := lv_stmt || ' from PMU_ESLD_ESTD partition(PMU_M13_S14) e ,';
    lv_stmt := lv_stmt || ' PMU_ESLD_ESTD_SPPRO partition(PMU_M13_S14) a';
    lv_stmt := lv_stmt || ' where e.PART_ARRETE = '||lv_p_arrete ;
    lv_stmt := lv_stmt || ' AND e.PART_ENV = ''BCE''' ;
    lv_stmt := lv_stmt || ' AND e.PART_SESSION = '||lv_p_session ;
    lv_stmt := lv_stmt || ' and e.ID = a.ID_ESTD ';
    lv_stmt := lv_stmt || ' and e.CD_STATUT = ''VE'' ' ;
    lv_stmt := lv_stmt || ' and e.TYP_MONTANT = ''33'' ; ' ;
    execute immediate lv_stmt;
    END;
    Thanks

  • Execute immediate and "in" operator

    Hello!
    I want to pass varchar2 type argument to my procedure in format '1,2,3' where 1,2 and 3 are some IDs.
    And then, in procedure I write:
    stmt := 'select avg(PRICE) from ORDERS where ORDER_ID in (:Ids)';
    execute immediate stmt into APrice using ARGUMENT;
    I undersand, that this is incorrect, because where clause in executable query is
    "where ORDER_ID in ('1,2,3')" but not "where ORDER_ID in (1,2,3)".
    Is there any easy way how to solve such a problem?
    Maybe I should use other argument type?

    user10304317 wrote:
    I undersand, that this is incorrect, because where clause in executable query isIf you want to use a string you will have to concatenate it into dynamic sql:
    stmt := 'select avg(PRICE) from ORDERS where ORDER_ID in (' || ARGUMENT || ')';
    execute immediate stmt into APrice;However, it will produce as many sql in shared pool as you will have different ARGUMENT values and each of them will do a hard parse. Or you could use collection and then you do not need dynamic sql (unless select list and/or rest of where clause is dynamic):
    SQL> create or replace
      2    type num_tbl_type
      3      as
      4        table of number;
      5  /
    Type created.
    SQL> create or replace procedure p1(
      2                                 p_num_tbl num_tbl_type
      3                                )
      4    is
      5    begin
      6        for rec in (select empno,ename from emp where empno in (select * from table(p_num_tbl))) loop
      7          dbms_output.put_line(rpad(rec.empno,10) || rec.ename);
      8        end loop;
      9  end;
    10  /
    Procedure created.
    SQL> set serveroutput on
    SQL> exec p1(num_tbl_type(7566,7839,7902))
    7566      JONES
    7839      KING
    7902      FORD
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Execute Immediate and CLOB

    Hi All,
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    I am getting error when trying to use CLOB with execute immediate.
    DECLARE
    v_clob CLOB;
    BEGIN
    EXECUTE IMMEDIATE 'SELECT DBMS_METADATA.GET_DDL(''TABLE'',''T_FDB_TMP'') from dual'
               INTO v_clob_part_ddl;
    EXECUTE IMMEDIATE 'DROP TABLE T_FDB_TMP';
    EXECUTE IMMEDIATE to_char(v_clob_part_ddl);
    END;
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at line 1
    ORA-06502: PL/SQL: numeric or value error
    ORA-31605: the following was returned from LpxXSLResetAllVars in routine kuxslResetParams:
    LPX-1: NULL pointer
    ORA-06512: at line 3
    06502. 00000 -  "PL/SQL: numeric or value error%s"Please help

    If you can't upgrade to 11g then you'll have to use DBMS_SQL package...
    e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_large_sql  CLOB;
      3    v_num        NUMBER := 0;
      4    v_upperbound NUMBER;
      5    v_sql        DBMS_SQL.VARCHAR2S;
      6    v_cur        INTEGER;
      7    v_ret        NUMBER;
      8  begin
      9    -- Build a very large SQL statement in the CLOB
    10    LOOP
    11      IF v_num = 0 THEN
    12        v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
    13      ELSE
    14        v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
    15      END IF;
    16      v_num := v_num + 1;
    17      EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
    18    END LOOP;
    19    DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
    20    DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
    21    --
    22    -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
    23    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
    24    FOR i IN 1..v_upperbound
    25    LOOP
    26      v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
    27                                 ,256 -- amount
    28                                 ,((i-1)*256)+1 -- offset
    29                                 );
    30    END LOOP;
    31    --
    32    -- Now parse and execute the SQL statement
    33    v_cur := DBMS_SQL.OPEN_CURSOR;
    34    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
    35    v_ret := DBMS_SQL.EXECUTE(v_cur);
    36    DBMS_OUTPUT.PUT_LINE('View Created');
    37* end;
    SQL> /
    Length:40015
    Num:548
    View Created
    PL/SQL procedure successfully completed.
    SQL> select count(*) from vw_tmp;
      COUNT(*)
           548
    SQL> select * from vw_tmp where rownum <= 10;
    COL1
    The number of this row is : 0000000
    The number of this row is : 0000001
    The number of this row is : 0000002
    The number of this row is : 0000003
    The number of this row is : 0000004
    The number of this row is : 0000005
    The number of this row is : 0000006
    The number of this row is : 0000007
    The number of this row is : 0000008
    The number of this row is : 0000009
    10 rows selected.
    SQL>

  • Difficulties with execute immediate and 'in' clause

    Hello all,
    I have some SQL that will have to run dynamically, which I can get to work by building a long statement, then getting it hard-parsed
    example:
    sql_stmt VARCHAR2(256) :=
    'select distinct some_id from table1
    where lname = ''Smith''
    and fname in(''Joe'', ''Joey'', ''Joseph'')
    and ssn = 111223333';
    execute immediate sql_stmt into new_id_value;
    the above state executes fine and returns the desired result.
    HOWEVER, when I try to use bind variables (this statement will be called several million times), I get a no rows returned error.
    I use bind variables as follows:
    sql_stmt VARCHAR2(256);
    vlname VARCHAR2(50) := 'Smith';
    vssn NUMBER := 111223333;
    vfname VARCHAR2(100) := '''Joe'', ''Joey'', ''Joseph''';
    sql_stmt :=
    'select distinct some_id from table1
    where lname = :vlname
    and fname in(:vfname)
    and ssn = :vssn;
    execute immediate sql_stmt into new_id_value
    using vlname, vfname, vssn;
    I know the issue involves the 'in' clause because I've substituted hardcoded values in and it has worked.
    any suggestions?

    Well maybe its all a little confusing, does an end to end demo make it any clearer Mr Bidness?
    SQL> create or replace type tabstr_t as table of varchar2(4000)
      2  /
    Type created.
    SQL> create or replace function tabstr (
      2      p_str in varchar2,
      3      p_sep in varchar2 default ','
      4      )
      5  return tabstr_t
      6  is
      7      l_str long := p_str || p_sep;
      8      l_tabstr tabstr_t := tabstr_t();
      9  begin
    10      while l_str is not null loop
    11          l_tabstr.extend(1);
    12          l_tabstr(l_tabstr.count) := rtrim(substr(
    13                  l_str,1,instr(l_str,p_sep)),p_sep);
    14          l_str := substr(l_str,instr(l_str,p_sep)+1);
    15      end loop;
    16      return l_tabstr;
    17  end;
    18  /
    Function created.
    SQL> var s varchar2(100)
    SQL> exec :s := 'king,turner,ward'
    PL/SQL procedure successfully completed.
    SQL> select ename, sal from emp
      2  where ename in (
      3    select upper(column_value) from
      4    table(cast(tabstr(:s) as tabstr_t))
      5    );
    ENAME             SAL
    KING             5000
    TURNER           1500
    WARD             1250
    SQL> exec :s := 'jones,blake,clark'
    PL/SQL procedure successfully completed.
    SQL> /
    ENAME             SAL
    BLAKE            2850
    CLARK            2450
    JONES            2975

  • Execute Immediate and the in list

    Hello,
    How do I format the in list when i am executing a query with execute immediate ?
    I want to check if a character value is in ('5', '6', '7') ? Execute immediate treats my in list as a string instead of checking to see if the given value is in ny list of values or not. Please see the code / output below.
    SQL> declare
    2
    3 v_result VARCHAR2 (1) := 'N';
    4 v_num_list1 VARCHAR2 (40) := '''5''';
    5 v_num_list2 VARCHAR2 (40) := '''5'',''6'',''7''';
    6
    7 v_in VARCHAR2 (100)
    8 := 'BEGIN IF (:txn_value IN (:case_list)) THEN :result := ''Y''; END IF; END;';
    9 v_ctrl_no varchar2(40) := '''5''';
    10 BEGIN
    11
    12 DBMS_OUTPUT.PUT_LINE ('txn_value: ' || v_ctrl_no);
    13 DBMS_OUTPUT.PUT_LINE ('case_list: ' || v_num_list1);
    14
    15 EXECUTE IMMEDIATE v_in
    16 USING IN v_ctrl_no, v_num_list1, OUT v_result;
    17
    18 DBMS_OUTPUT.PUT_LINE ('result is ''' || v_result || '''');
    19 v_result := 'N';
    20
    21 DBMS_OUTPUT.PUT_LINE ('txn_value: ' || v_ctrl_no);
    22 DBMS_OUTPUT.PUT_LINE ('case_list: ' || v_num_list2);
    23
    24 EXECUTE IMMEDIATE v_in
    25 USING IN v_ctrl_no, v_num_list2, OUT v_result;
    26
    27 DBMS_OUTPUT.PUT_LINE ('result is ''' || v_result || '''');
    28
    29 END;
    30 /
    txn_value: '5'
    case_list: '5'
    result is 'Y'
    txn_value: '5'
    case_list: '5','6','7'
    result is 'N'
    Thanks,
    Anna

    you can't use a bind variable for an in-list string.
    you can rebuild the dynamic statement each time, without a bind variable:
    sql := '... in ( ' || in_list_var ||' )...
    or, you can use instr:
    sql := ' ... instr(:in_list_var, :txn_val) > 0 ...'
    using ','||in_list, ','||txn_val||','; -- notice the extra commas

  • EXECUTE IMMIDIATE AND INSERT?

    Hi ALL,
    I want to know the difference between Execute Immediate and Insert statement???

    Hi,
    Welcome to the forum!
    Insert: add rows to a table, the base table of a view, a partition of a partitioned table or a subpartition of a composite-partitioned table, or an object table or the base table of an object view (more information: INSERT)
    Execute immediate: builds and executes a dynamic SQL statement in a single operation. It is the means by which native dynamic SQL processes most dynamic SQL statements (more information: [EXECUTE IMMEDIATE|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/executeimmediate_statement.htm#i33888])
    Regards,

  • Problem in Update statement using Execute Immediate

    Hi All,
    I am facing problem in update statement.
    I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
    But it is not updating any thing there in the table.
    I have created a query like :
    update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
    Execute immediate update_query using V_Id;
    commit;
    But it is not updating the table.
    I have a question , is execute immediate only does insert and delete?
    Thanks
    Ashok

    SQL> select * from t;
                     TID P
                     101 N
    SQL> declare
      2     V_Id          number := 101;
      3     Table_Name    varchar2(30) := 'T';
      4     update_query  varchar2(1000);
      5  begin
      6     update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
      7     Execute immediate update_query using V_Id;
      8     commit;
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> select * from t;
                     TID P
                     101 Y                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Column Order Execute Immediate

    I am trying to alter a table to add columns in a specific order. When I run the below statement, it always makes the first column (ORA_ERR_NUMBER$) the last column in the actual order of the table. Why is this? Some kind of bug?
    create procedure test
    as
    sqlstmt varchar2(2000);
    BEGIN
    sqlstmt := 'ALTER TABLE test.ERR$_F00165 ADD (ORA_ERR_NUMBER$ NUMBER, ORA_ERR_MESG$ VARCHAR2(2000 BYTE), ORA_ERR_ROWID$ UROWID(4000), ORA_ERR_OPTYPE$ VARCHAR2(2 BYTE), ORA_ERR_TAG$ VARCHAR2(2000 BYTE))';
    EXECUTE IMMEDIATE sqlstmt;
    END;

    Purge recyclebin doesn't help. Not sure what else it could be. I don't think it has anything to do with my script but it is below for reference.
    create or replace
    procedure Merge811_sp
    AUTHID CURRENT_USER
    as
    sqlstmtC varchar2(2000);
    sqlstmtI varchar2(2000);
    sqlstmtL varchar2(2000);
    sqlstmtCnt varchar2(2000);
    sqlstmtCnt2 varchar2(2000);
    sqlstmtLOB varchar2(2000);
    sqlstmtLOBCat varchar2(2000);
    sqlstmtLOBCat2 varchar2(2000);
    sqlstmtLOBCat3 varchar2(2000);
    CountVar number;
    CountVar2 number;
    LOBCommaList varchar2(2000);
    BEGIN
    declare
    cursor c8 is
    --select src and dest tables where table group is 2 and active = Y
    select TABLE_NAME, TABLE_SRC_SCHEMA, TABLE_DEST_SCHEMA
    from testschema.TEST_TABLES where TABLE_ACTIVE = 'Y'
    and TABLE_GROUP = 2
    order by TABLE_NAME;
    begin
    for r_c8 in c8 loop
    BEGIN
    sqlstmtCnt := 'select count(*) into :CountVar from dba_tables where table_name = ''ERR$_'||r_c8.TABLE_NAME||''' and owner = '''||r_c8.TABLE_DEST_SCHEMA||''';';
    EXECUTE IMMEDIATE 'BEGIN '||sqlstmtCnt||' END;' USING OUT CountVar;
    --If error table does not exist.......
    IF CountVar = 0
    THEN
    sqlstmtCnt2 := 'select count(*) into :CountVar2 from dba_tables a join dba_tab_columns b ON a.table_name = b.table_name and a.owner = b.owner
    where a.table_name = '''||r_c8.TABLE_NAME||''' and
    a.owner = '''||r_c8.TABLE_SRC_SCHEMA||''' and b.DATA_TYPE in (''BLOB'', ''CLOB'', ''LONG'', ''LONG RAW'', ''NCLOB'');';
    --dbms_output.put_line(sqlstmtCnt2);
    EXECUTE IMMEDIATE 'BEGIN '||sqlstmtCnt2||' END;' USING OUT CountVar2;
    --If no LOB or LONG data types, create error table and insert data with logging
    IF CountVar2 = 0
    THEN
    sqlstmtC := 'DBMS_ERRLOG.create_error_log (dml_table_name => '''||r_c8.TABLE_DEST_SCHEMA||'.'||r_c8.TABLE_NAME||''');';
    --dbms_output.put_line(sqlstmtC);
    EXECUTE IMMEDIATE ('BEGIN '||sqlstmtC||' END;');
    --commit;
    sqlstmtI := 'INSERT INTO '||r_c8.TABLE_DEST_SCHEMA||'.'||r_c8.TABLE_NAME||' SELECT * FROM '||r_c8.TABLE_SRC_SCHEMA||'.'||r_c8.TABLE_NAME||' LOG ERRORS INTO '||r_c8.TABLE_DEST_SCHEMA||'.ERR$_'||r_c8.TABLE_NAME||' (''811UPGRADE_Grp2'') REJECT LIMIT UNLIMITED;';
    --dbms_output.put_line(sqlstmtI);
    EXECUTE IMMEDIATE('BEGIN '||sqlstmtI||' END;');
    commit;
    END IF;
    --If LOB or LONG data types exist, create error table without them and then insert with logging 
    IF CountVar2 > 0
    THEN
    sqlstmtLOB := 'SELECT LTRIM(SYS_CONNECT_BY_PATH(myvalues, '''||','||'''),'''||','||''') into :LOBCommaList
    FROM (SELECT myvalues, ROW_NUMBER() OVER (ORDER BY myvalues) rn, COUNT(*) OVER () cnt
    FROM (SELECT column_name as myvalues
    FROM dba_tables a join dba_tab_columns b ON a.table_name = b.table_name and a.owner = b.owner
    where a.table_name = '''||r_c8.TABLE_NAME||''' and
    a.owner = '''||r_c8.TABLE_SRC_SCHEMA||''' and b.DATA_TYPE not in (''BLOB'', ''CLOB'', ''LONG'', ''LONG RAW'', ''NCLOB'') )) data
    WHERE rn = cnt
    START WITH rn = 1
    CONNECT BY PRIOR rn = rn-1;';
    EXECUTE IMMEDIATE 'BEGIN '||sqlstmtLOB||' END;' USING OUT LOBCommaList;
    sqlstmtLOBCat := 'CREATE TABLE '||r_c8.TABLE_DEST_SCHEMA||'.ERR$_'||r_c8.TABLE_NAME||' AS SELECT '||LOBCommaList||' FROM '||r_c8.TABLE_SRC_SCHEMA||'.'||r_c8.TABLE_NAME||' WHERE 1 = 0';
    EXECUTE IMMEDIATE sqlstmtLOBCat;
    sqlstmtLOBCat2 := 'ALTER TABLE '||r_c8.TABLE_DEST_SCHEMA||'.ERR$_'||r_c8.TABLE_NAME||' ADD (ORA_ERR_NUMBER$ NUMBER, ORA_ERR_MESG$ VARCHAR2(2000 BYTE), ORA_ERR_ROWID$ UROWID(4000), ORA_ERR_OPTYPE$ VARCHAR2(2 BYTE), ORA_ERR_TAG$ VARCHAR2(2000 BYTE))';
    EXECUTE IMMEDIATE sqlstmtLOBCat2;
    sqlstmtL := 'INSERT INTO '||r_c8.TABLE_DEST_SCHEMA||'.'||r_c8.TABLE_NAME||' SELECT * FROM '||r_c8.TABLE_SRC_SCHEMA||'.'||r_c8.TABLE_NAME||' LOG ERRORS INTO '||r_c8.TABLE_DEST_SCHEMA||'.ERR$_'||r_c8.TABLE_NAME||' (''811UPGRADE_Grp2'') REJECT LIMIT UNLIMITED;';
    EXECUTE IMMEDIATE('BEGIN '||sqlstmtL||' END;');
    commit;
    END IF;
    END IF;
    END;

  • How can I debug a Bulk Insert error?

    I'm loading a bunch of files into SQL server.  All work fine, but one keeps erroring out on me.  All files should be exactly the same in structure, but they have different dates, and other different financial metrics, but the structure and field
    names should be exactly the same.  Nevertheless, one keeps konking out, and throwing this error.
    Msg 4832, Level 16, State 1, Line 1
    Bulk load: An unexpected end of file was encountered in the data file.
    Msg 7399, Level 16, State 1, Line 1
    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Msg 7330, Level 16, State 2, Line 1
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
    The ROWTERMINATOR should be CRLF, and when you look at it in Notepad++ that's what it looks like, but it must be something else, because I keep getting errors here.  I tried the good old:  ROWTERMINATOR='0x0a'
    That works on all files, but one, so there's something funky going on here, and I need to see what SQL Server is really doing.
    Is there some way to print out a log, or look at a log somewhere?
    Thanks!!
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    The first thing to try is to see if BCP likes the file. BCP and BULK INSERT adhere to the same spec, but they are different implementations, but there are subtle differences.
    There is an ERRORFILE option, but it more helps when there is bad data.
    You can also use the BATCHSIZE option to see how many records in the file it swallows, before things go bad. FIRSTROW and LASTROW can also help.
    All in all, it can be quite tedious find that single row where things are different - and where BULK INSERT loses sync entirely. Keep in mind that it reads fields on by one, and it there is one field terminator to few on a line, it will consume the line
    feed at the end of the line as data.
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for

  • Converting files with Camera Raw 4.1

    Have just upgraded to iphoto '08, and am having problems with "noise" in the raw conversion within iphoto. So, I'm using Camera Raw 4.1 instead (a bit of a pain as I have a batch of 200 photos to convert from a wedding!). A question ... can you save

  • New W 510 AC Adapter

    I just got my new ac adapter or power supply with the new W 510.  This power supply is too  big.  It says it is 7 amps and with the i7 chip onboard the TP maybe it needs it.  I tried running the power adapter from my older W500 but the new computer s

  • SSH from Cisco Router to another Cisco Router

    I believe I already know what the issue is but wanted to confirm. I recently changed the configuration of the routers so that all incoming SSH connections can only be done via the specified port: ip ssh port xxxx rotary 10 created an ACL and everythi

  • Need to Parse XML Message from my Message Driven Bean

    Hi I am using Message Driven Beans for listening to a Queue . I am getting a Big XML file from my Queue in form of a TextMessage . Now my task is to read / parse the XML Message . Please tell me what is the appropiate parsing technique i need to use

  • HP photo smart 7520 all in one printer error. B8867448.

    Screen flashing. Message "printer error. There is a problem with the printer. Turn the printer off, then on". When it is turned off, then on, the blue Hewlett Packard screen flashes with B8867448, then it returns to error message. This question was s