ROWCOUNT in BULK Insert Statement

Hi,
I'm using in a BULK INSERT statement in a PL/SQL procedure and after execution of the SQL statement,I need to capture the row count.
Same is the case for UPDATE.
The Example code is as mentioned below:
INSERT INTO TBL1
(SELECT VAL1,VAL2 FROM TBL2)
No. of rows inserted needs to be retrieved after execution of this SQL.
Please let me know if there is any way to do it.
Thanks.

SQL> create table emp as select * from scott.emp where 1 = 0 ;
Table created.
SQL> set serveroutput on
SQL> begin
  2    insert into emp select * from scott.emp ;
  3    dbms_output.put_line('Count='||SQL%RowCount) ;
  4  end ;
  5  /
Count=14
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • How to change Bulk Insert statement from MS SQL to Oracle

    Hi All,
    Good day, I would like to bulk insert the content of a file into Oracle db. May I know how to change the below MS SQL syntax to Oracle syntax?
    Statement statement = objConnection.createStatement();
    statement.execute("BULK INSERT [TBL_MERCHANT] FROM '" MERCHANT_FILE_DIR "' WITH ( FIELDTERMINATOR = '~~', ROWTERMINATOR = '##' )");
    Thanks in advance.
    cs.

    Oracle SQL Loader utility allows you to insert data from flat file to database tables.
    Go to SQL Loader links on following url to learn more on this utility
    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/toc.htm
    Chandar

  • Pro*C compilation error - bulk insert statement

    Guys, I am screwed up!
    There's this Pro*C application that I am working on. I made some changes in some of the functions and when I compile using Pro*C pre-compiler (Version 9), it throws an error in one of the modules that I have not even touched.
    Following is the error:
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ++: Release 9.0.1.1.1 - Production on Fri May 25 20:35:30 2007
    (c) Copyright 2001 Oracle Corporation. All rights reserved.
    System default option values taken from: C:\oracle\ora90\precomp\admin\pcscfg.cfg
    Error at line 1512, column 1 in file D:\Siemens\GABS-R\Source\GSM-R_Rating\RTLRa
    ting\multimainrate_supp1_cug.pc
    EXEC SQL FOR :record_roaming
    1
    PLS-S-00382, expression is of wrong type
    Error at line 1512, column 1 in file D:\Siemens\GABS-R\Source\GSM-R_Rating\RTLRa
    ting\multimainrate_supp1_cug.pc
    EXEC SQL FOR :record_roaming
    1
    PLS-S-00000, SQL Statement ignored
    Semantic error at line 1512, column 1, file D:\Siemens\GABS-R\Source\GSM-R_Rating\RTLRating\multimainrate_supp1_cug.pc:
    EXEC SQL FOR :record_roaming
    1
    PCC-S-02346, PL/SQL found semantic errors
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    The location it is referring to is:
    EXEC SQL FOR :record_roaming
    INSERT /*+ PARALLEL(GT_RATED_ROAMING_CALLS) */
    INTO GT_RATED_ROAMING_CALLS
    (GF_SEQ_NO,
    GF_CALL_PRODUCT,
    GF_CDR_TYPE,
    GF_REC_NO,
    GF_REC_STAT,
    GF_INTER_REC_NO,
    GF_SS_REC_NO,
    GF_SS_CODE,
    GF_CALLING_NUM,
    GF_CALLED_NUM,
    GF_CALLING_IMSI,
    GF_CALLED_IMSI,
    GF_CALLED_NUM_TON,
    GF_DIALLED_DIGITS,
    GF_LAC,
    GF_CELL,
    GF_IN_CKTGRP,
    GF_IN_CKTID,
    GF_OUT_CKTGRP,
    GF_OUT_CKTID,
    GF_BS_TYPE,
    GF_BS_CODE,
    GF_DURATION,
    GF_THREAD_ID,
    GF_CARRIER,
    GF_AIR_TIM_CHARGE,
    GF_TOLL_CHARGE,
    GF_TOLL_UNITS,
    GF_ROAM_SURCHARGE,
    GF_ROAMING_CHARGES,
    GF_ADDITIONAL_CHARGES,
    GF_CUST_ID,
    GF_CONT_ID,
    GF_BILL_PRD,
    GF_STATUS,
    GF_ERROR_CODE,
    GF_RECON_STAT_LANDLINE,
    GF_RECON_STAT_ROAMING,
    GF_CALLING_IMEI,
    GF_CALLED_IMEI,
    GF_MSC_ID,
    GF_ACTION_CODE,
    GF_MSRN,
    GF_LONG_DISTANCE_AIR_CHRG,
    gf_home_zone_surcharge,
    GF_SWITCH_CODE,
    GF_BILL_DATE,
    GF_CITY_CODE,
    GF_BILL_FREQ,
    GF_CALL_START_DATE,
    GF_CALL_END_DATE,
    GF_SMS_TEXT,
    GF_TIME_STAMP_AVAILABLE,
    GF_TYPE_OF_CALL,
    GF_PEAK_OFFPEAK,
    GF_PROCESS_DATE,
    GF_MATCH_DATA,
    GF_ORIG_ZONE_CODE,
    GF_DEST_ZONE_CODE,
    GF_PRICE_PLAN_CODE
    values
    (:gt_rated_roaming_calls,sysdate,:roaming_details_match_data,:l_gf_rcd_zone,:l_gf_price_plan);
    Pls note that the host variables match exactly the number of fields in the INTO clause (anyway, the error in such a case is different).
    Please save my soul!
    Sanchit

    Hi, check Metalink Note 451413.1 Pro*C Build Fails With Error PCC-02014 on File /usr/include/standards.h
    I did workarround #2, and worked.
    *+<Moderator edi t- deleted MOS Doc content - pl do NOT post contents of MOS Docs - this is a violation of your Support agreement>+*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Reduce time consumption of a bulk insert statement

    Hi All,
    I am trying to insert some large amount of data records into a Global Temporary Table (GTT) using a query like below. Below SQL statement is generated as a string and executed as a dynamic sql statement.
    INSERT INTO
    my_table ( col1, col2, col3, col4)
    SELECT c1, c2, c3, c4
    FROM tab1 t1,
    tab2 t2,
    tab3 t3
    WHERE <<dynamically generated where clause>>
    UNION ALL
    SELECT c1, c2, c3, c4
    FROM tab4 t4,
    tab5 t5,
    tab6 t6
    WHERE <<dynamically generated where clause>>
    UNION ALL
    SELECT c1, c2, c3, c4
    FROM tab4 t4,
    tab5 t5,
    tab6 t6
    WHERE <<dynamically generated where clause>>
    UNION ALL
    SELECT c1, c2, c3, c4
    FROM tab4 t4,
    tab5 t5,
    tab6 t6
    WHERE <<dynamically generated where clause>>
    The problem is, it takes some considerable amount of time(25-30 seconds) to write the resulted data set into GTT(my_table ). I have checked the SELECT statement above (without the INSERT), and it gives the result set in few seconds. Therefore i assume it's the INSERT that takes more time. (SELECT statement returns around 75000+ records). The GTT consists of 8 columns and 6 out of those are marked as a primary key.
    Are there any other mechanisms that I can use to efficiently insert large amount of data in to the table? Really appreciate all of your comments and suggestions.
    Best Regards,
    Nipuna

    Hi,
    I'm not sure about your query speed :) Don't have it against me, but sometimes users just run SELECT statement and waits unitl first rows are returned (e.g. using TOAD which fetches 500 first rows as default) and they are convinced that this is response time for whole set. You have to navigate to last record to see real response time. But probably this is not the casse here. When you insert a large set of data consider to move such statement from forms to database (you avoid data roundtrip between forms and DB). If your insert still takes to much time then try to trace session you run your statement and(if possible) try to monitor your database resource ussge. If you're not able to use dbms_trace then you can just lokk at the system v$Session views. Following two views can be helpful to investigate most time consuming waits and can help understand the reason of slowness.
    select * from v$session_wait
    select * from v$session_wait_history

  • Rowcount for multiple insert statements

    Hi all,
    Is there a way I can get separate rowcount in multi table insert?
    My sql is written as below:
        INSERT ALL
          INTO TAB1 (COL1, COL2....)  VALUES          (VAL1, VAL2....)
          INTO TAB2 (COL1, COL2....)  VALUES          (VAL1, VAL2....)
            (SELECT * FROM TABLE);
    rowcount of tab1?
    rowcount of tab2?
    Thank you,
    Niroop

    Here is the work around to get the multi-table insert counts.
    SQL>
    SQL> select * from v$version;
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production   
    PL/SQL Release 11.2.0.1.0 - Production                                         
    CORE    11.2.0.1.0    Production                                                     
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production                        
    NLSRTL Version 11.2.0.1.0 - Production                                         
    SQL>
    SQL> DROP PACKAGE utils_pkg;
    Package dropped.
    SQL> DROP TABLE src_tab;
    Table dropped.
    SQL> DROP TABLE tab1;
    Table dropped.
    SQL> DROP TABLE tab2;
    Table dropped.
    SQL>
    SQL> CREATE OR REPLACE
      2  PACKAGE utils_pkg
      3  IS
      4    v_tab1_rec_count pls_integer :=0;
      5    v_tab2_rec_count pls_integer :=0;
      6    FUNCTION fCounter(
      7        pTab_Name IN VARCHAR2)
      8      RETURN NUMBER;
      9    FUNCTION fGetInsCounts(
    10        pTab_Name IN VARCHAR2)
    11      RETURN NUMBER;
    12    FUNCTION fResetCounts
    13      RETURN NUMBER;
    14  END utils_pkg;
    15  /
    Package created.
    SQL> CREATE OR REPLACE
      2  PACKAGE body utils_pkg
      3  IS
      4  FUNCTION fcounter(
      5      pTab_Name IN VARCHAR2)
      6    RETURN NUMBER
      7  IS
      8  BEGIN
      9    IF pTab_Name        = 'TAB1' THEN
    10      v_tab1_rec_count := v_tab1_rec_count +1;
    11    ELSE
    12      v_tab2_rec_count := v_tab2_rec_count +1;
    13    END IF;
    14    RETURN 0;
    15  END fcounter;
    16  FUNCTION fGetInsCounts(
    17      pTab_Name IN VARCHAR2)
    18    RETURN NUMBER
    19  IS
    20  BEGIN
    21    IF pTab_Name = 'TAB1' THEN
    22      RETURN v_tab1_rec_count;
    23    ELSE
    24      RETURN v_tab2_rec_count;
    25    END IF;
    26  END fGetInsCounts;
    27  FUNCTION fResetCounts
    28    RETURN NUMBER
    29  IS
    30  BEGIN
    31    v_tab1_rec_count :=0;
    32    v_tab2_rec_count :=0;
    33    RETURN NULL;
    34  END fResetCounts;
    35  END utils_pkg;
    36  /
    Package body created.
    SQL> CREATE TABLE src_tab AS
      2  SELECT *
      3  FROM
      4    (SELECT 1 col1, 'TEST' col2, 'TAB2_DATA' col3 FROM dual
      5    UNION ALL
      6    SELECT 2, 'TESTING', 'NO_TAB2_DATA' FROM dual
      7    )temp;
    Table created.
    SQL>
    SQL> CREATE TABLE tab1 AS
      2  SELECT col1, col2 FROM src_tab WHERE 1=2;
    Table created.
    SQL>
    SQL> CREATE TABLE tab2 AS
      2  SELECT col3 FROM src_tab WHERE 1=2;
    Table created.
    SQL>
    SQL> SELECT utils_pkg.fGetInsCounts('TAB1') AS tab1_inserts,
      2    utils_pkg.fGetInsCounts('TAB2')      AS tab2_inserts,
      3    utils_pkg.fresetcounts    AS reset_done
      4  FROM dual;
    TAB1_INSERTS TAB2_INSERTS RESET_DONE                                           
               0            0                                                      
    SQL>
    SQL> INSERT ALL
      2  INTO tab1
      3    (
      4      col1,
      5      col2
      6    )
      7    VALUES
      8    (
      9      DECODE(utils_pkg.fcounter('TAB1'),0,col1),
    10      col2
    11    )
    12  INTO tab2
    13    (
    14      col3
    15    )
    16    VALUES
    17    (
    18      DECODE(utils_pkg.fcounter('TAB2'),0,col3)
    19    )
    20  SELECT col1, col2, col3 FROM src_tab;
    4 rows created.
    SQL>
    SQL>
    SQL> SELECT utils_pkg.fGetInsCounts('TAB1') AS tab1_inserts,
      2    utils_pkg.fGetInsCounts('TAB2')      AS tab2_inserts,
      3    utils_pkg.fresetcounts    AS reset_done
      4  FROM dual;
    TAB1_INSERTS TAB2_INSERTS RESET_DONE                                           
               2            2                                                      
    SQL>
    SQL> rollback;
    Rollback complete.
    SQL>
    SQL> INSERT  WHEN 1=1 THEN
      2  INTO tab1
      3    (
      4      col1,
      5      col2
      6    )
      7    VALUES
      8    (
      9      DECODE(utils_pkg.fcounter('TAB1'),0,col1),
    10      col2
    11    )
    12    WHEN col3 = 'TAB2_DATA' THEN
    13  INTO tab2
    14    (
    15      col3
    16    )
    17    VALUES
    18    (
    19      DECODE(utils_pkg.fcounter('TAB2'),0,col3)
    20    )
    21  SELECT col1, col2, col3 FROM src_tab;
    3 rows created.
    SQL>
    SQL>
    SQL> SELECT utils_pkg.fGetInsCounts('TAB1') AS tab1_inserts,
      2    utils_pkg.fGetInsCounts('TAB2')      AS tab2_inserts,
      3    utils_pkg.fresetcounts    AS reset_done
      4  FROM dual;
    TAB1_INSERTS TAB2_INSERTS RESET_DONE                                           
               2            1                                                      
    SQL>
    SQL> rollback;
    Rollback complete.
    Thanks,
    GPU

  • ODBC, bulk inserts and dynamic SQL

    I am writing an application running on Windows NT 4 and using the oracle ODBC driver (8.01.05.00, that inserts many rows at a time (10000+) into an oracle 8i database.
    At present, I am using a stored procedure to insert each row into the database. The stored procedure uses dynamic SQL because I can only determine the table and field names at run time.
    Due to the large number of records, it tends to take a while to perform all the inserts. I have tried a number of solutions such as using batches of SQL statements (e.g. "INSERT...;INSERT...;INSERT..."), but the oracle ODBC driver only seems act on the first statement in the batch.
    I have also considered using the FOR ALL statement and SQL*Loader utility.
    My problem with FOR ALL is that I'm not sure it works on dynamic SQL statements and even if it did, how do I pass an array of statements to the stored procedure.
    I ruled out SQL* Loader because I could not find a way to invoke it it from an ODBC statement. Secondly, it requires the spawining of a new process.
    What I am really after is something similar the the SQL Server (forgive me!) BULK INSERT statement where you can simply create an input file with all the records you want to insert, and pass it along in an ODBC statement such as "BULK INSERT <filename>".
    Any ideas??
    null

    Hi,
    I faced this same situation years ago (Oracle 7.2!) and had the following alternatives.
    1) Use a 3rd party tool such as Sagent or CA Info pump (very pricey $$$)
    2) Use VisualC++ and OCI to hook into the array insert routines (there are examples of these in the Oracle Home).
    3) Use SQL*Loader (the best performance, but no real control of what's happening).
    I ended up using (2) and used the Rouge Wave dbtools.h++ library to speed up the development.
    These days, I would also suggest you take a look at Perl on NT (www.activestate.com) and the DBlib modules at www.perl.org. I believe they will also do bulk loading.
    Your problem is that your program is using Oracle ODBC, when you should be using Oracle OCI for best performance.
    null

  • Bulk inserts and dynamic SQL

    I am writing an application running on Windows NT 4 and using the oracle ODBC driver (8.01.05.00, that inserts many rows at a time (10000+) into an oracle 8i database.
    At present, I am using a stored procedure to insert each row into the database. The stored procedure uses dynamic SQL because I can only determine the table and field names at run time.
    Due to the large number of records, it tends to take a while to perform all the inserts. I have tried a number of solutions such as using batches of SQL statements (e.g. "INSERT...;INSERT...;INSERT..."), but the oracle ODBC driver only seems act on the first statement in the batch.
    I have also considered using the FOR ALL statement and SQL*Loader utility.
    My problem with FOR ALL is that I'm not sure it works on dynamic SQL statements and even if it did, how do I pass an array of statements to the stored procedure.
    I ruled out SQL* Loader because I could not find a way to invoke it it from an ODBC statement. Secondly, it requires the spawining of a new process.
    What I am really after is something similar the the SQL Server (forgive me!) BULK INSERT statement where you can simply create an input file with all the records you want to insert, and pass it along in an ODBC statement such as "BULK INSERT <filename>".
    Any ideas??
    null

    Hi,
    I faced this same situation years ago (Oracle 7.2!) and had the following alternatives.
    1) Use a 3rd party tool such as Sagent or CA Info pump (very pricey $$$)
    2) Use VisualC++ and OCI to hook into the array insert routines (there are examples of these in the Oracle Home).
    3) Use SQL*Loader (the best performance, but no real control of what's happening).
    I ended up using (2) and used the Rouge Wave dbtools.h++ library to speed up the development.
    These days, I would also suggest you take a look at Perl on NT (www.activestate.com) and the DBlib modules at www.perl.org. I believe they will also do bulk loading.
    Your problem is that your program is using Oracle ODBC, when you should be using Oracle OCI for best performance.
    null

  • [Forum FAQ] How to use multiple field terminators in BULK INSERT or BCP command line

    Introduction
    Some people want to know if we can have multiple field terminators in BULK INSERT or BCP commands, and how to implement multiple field terminators in BULK INSERT or BCP commands.
    Solution
    For character data fields, optional terminating characters allow you to mark the end of each field in a data file with a field terminator, as well as the end of each row with a row terminator. If a terminator character occurs within the data, it is interpreted
    as a terminator, not as data, and the data after that character is interpreted and belongs to the next field or record. I have done a test, if you use BULK INSERT or BCP commands and set the multiple field terminators, you can refer to the following command.
    In Windows command line,
    bcp <Databasename.schema.tablename> out “<path>” –c –t –r –T
    For example, you can export data from the Department table with bcp command and use the comma and colon (,:) as one field terminator.
    bcp AdventureWorks.HumanResources.Department out C:\myDepartment.txt -c -t ,: -r \n –T
    The txt file as follows:
    However, if you want to bcp by using multiple field terminators the same as the following command, which will still use the last terminator defined by default.
    bcp AdventureWorks.HumanResources.Department in C:\myDepartment.txt -c -t , -r \n -t: –T
    The txt file as follows:
    When multiple field terminators means multiple fields, you use the below comma separated format,
    column1,,column2,,,column3
    In this occasion, you only separate 3 fields (column1, column2 and column3). In fact, after testing, there will be 6 fields here. That is the significance of a field terminator (comma in this case).
    Meanwhile, using BULK INSERT to import the data of the data file into the SQL table, if you specify terminator for BULK import, you can only set multiple characters as one terminator in the BULK INSERT statement.
    USE <testdatabase>;
    GO
    BULK INSERT <your table> FROM ‘<Path>’
     WITH (
    DATAFILETYPE = ' char/native/ widechar /widenative',
     FIELDTERMINATOR = ' field_terminator',
    For example, using BULK INSERT to import the data of C:\myDepartment.txt data file into the DepartmentTest table, the field terminator (,:) must be declared in the statement.
    In SQL Server Management Studio Query Editor:
    BULK INSERT AdventureWorks.HumanResources.DepartmentTest FROM ‘C:\myDepartment.txt’
     WITH (
    DATAFILETYPE = ‘char',
    FIELDTERMINATOR = ‘,:’,
    The new table contains like as follows:  
    We could not declare multiple field terminators (, and :) in the Query statement,  as the following format, a duplicate error will occur.
    In SQL Server Management Studio Query Editor:
    BULK INSERT AdventureWorks.HumanResources.DepartmentTest FROM ‘C:\myDepartment.txt’
     WITH (
    DATAFILETYPE = ‘char',
    FIELDTERMINATOR = ‘,’,
    FIELDTERMINATOR = ‘:’
    However, if you want to use a data file with fewer or more fields, we can implement via setting extra field length to 0 for fewer fields or omitting or skipping more fields during the bulk copy procedure.  
    More Information
    For more information about filed terminators, you can review the following article.
    http://technet.microsoft.com/en-us/library/aa196735(v=sql.80).aspx
    http://social.technet.microsoft.com/Forums/en-US/d2fa4b1e-3bd4-4379-bc30-389202a99ae2/multiple-field-terminators-in-bulk-insert-or-bcp?forum=sqlgetsta
    http://technet.microsoft.com/en-us/library/ms191485.aspx
    http://technet.microsoft.com/en-us/library/aa173858(v=sql.80).aspx
    http://technet.microsoft.com/en-us/library/aa173842(v=sql.80).aspx
    Applies to
    SQL Server 2012
    SQL Server 2008R2
    SQL Server 2005
    SQL Server 2000
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • Multiple field terminators in BULK INSERT or BCP

    Can i have multiple field terminators  in BULK INSERT or BCP commands i,e, define more than 1 for a file?
    Pls provide example.

    Hi stellios,
    For character data fields, optional terminating characters allow you to mark the end of each field in a data file with a field terminator and the end of each row with a row terminator. If a terminator character occurs within the data, it is interpreted as
    a terminator, not as data, and the data after that character is interpreted as belonging to the next field or record. I do a test, if you use BULK INSERT or BCP commands and set the multiple field terminators, you can refer to the following command.
    In Windows command line:
    bcp AdventureWorks.HumanResources.Department in C:\myDepartment.txt -c -t ,: -r \n –T
    ---you can use the two characters as one terminators, it can do well
    --if you want to bcp by using multiple field terminators just like the following command, it will still use the last terminator defined by default.
    bcp AdventureWorks.HumanResources.Department in C:\myDepartment.txt -c -t , -r \n -t: –T
    If you specify terminator for  BULK import. You can only set one terminator in the BULK INSERT statement.
    USE <testdatabase>;
    GO
    BULK INSERT <your table> FROM ‘<Path>’
       WITH (
    DATAFILETYPE = 'char',
    FIELDTERMINATOR = ',',
    ROWTERMINATOR = '\n'
    GO
    For more information about filed terminators, you can review the following article.
    http://technet.microsoft.com/en-us/library/aa196735(v=sql.80).aspx
    http://technet.microsoft.com/en-us/library/ms191485.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • FORALL bulk insert ..strange behaviour

    Hi all..
    I have the following problem..
    I use a FORALL bulk Insert statement to insert a set of values using a collection that has only one row. The thing is I get a ' ORA-01400: cannot insert NULL into <schema>.<table>.<column>' error message, whereas the row has been inserted into the table!
    Any ideas why this is happening?

    Here is the sample code..
    te strange thing is that the cursor has 1 row and the array gets also 1 row..
    FUNCTION MAIN() RETURN BOOLEAN IS
    -- This cursor retrieves all necessary values from CRD table to be inserted into PDCS_DEFERRED_RELATIONSHIP table
    CURSOR mycursor IS
    SELECT key1,
    key2,
    column1,
    date1,
    date2,
    txn_date
    FROM mytable pc
    WHERE
    -- create an array and a type for the scancrd cursor
    type t_arraysample IS TABLE OF mycursor%ROWTYPE;
    myarrayofvalues t_arraysample;
    TYPE t_target IS TABLE OF mytable%ROWTYPE;
    la_target t_target := t_target();
    BEGIN
    OPEN mycursor;
    FETCH mycursor BULK COLLECT
    INTO myarrayofvalues
    LIMIT 1000;
    myarrayofvalues.extend(1000);
    FOR x IN 1 .. myarrayofvalues.COUNT
    LOOP
    -- fetch variables into arrays
    gn_index := gn_index + 1;
    la_target(gn_index).key1 := myarrayofvalues(x).key1;
    la_target(gn_index).key2 := myarrayofvalues(x).key2;
    la_target(gn_index).column1 := myarrayofvalues(x).column1;
    la_target(gn_index).date1 := myarrayofvalues(x).date1;
         la_target(gn_index).date2 := myarrayofvalues(x).date2;
    la_target(gn_index).txn_date := myarrayofvalues(x).txn_date;
    END LOOP;
    -- call function to insert/update TABLE
    IF NOT MyFunction(la_target) THEN
    ROLLBACK;
    RAISE genericError;
         ELSE COMMIT;
    END IF;
    CLOSE mycursor;
    END IF;
    FUNCTION MyFunction(t_crd IN t_arraysample) return boolean;
    DECLARE
    BEGIN
    FORALL x IN la_target.FIRST..la_target.LAST
    INSERT INTO mytable
    VALUES la_target(x);
    END IF;

  • Using of bulk insert create problem

    How to use the bulk insert statement in my jsp and which should be updated into the database.
    I've tried this one:
    bulk insert test from test1.txt with (fieldterminator=':')but it gives an error as:
    u don't have permission to use bulk statement.
    Could any1 get me rid off from this problem.
    in advance thanks.....

    Most likely the person responsible for permissions in your database could help you out there. If you're here looking for a way to execute commands that you aren't authorized to execute, you are wasting your time.

  • Obtaining a rowcount from a csv file before bulk insert

    I have a group of csv files that i am bulk inserting into my sql table.  They are varying lengths, but the last seven lines of every file are not lines of data that comply with the format of my table and are causing insert errors.  I know i can
    specify a "lastrow" value for the bulk insert, but my problem is that i need a rowcount before running the statement and I can't seem to figure out a way of getting it with how im accessing the file.  (example below of what i'm doing without
    checking for the qty of rows):
    CREATE TABLE ALLFILENAMES(WHICHPATH VARCHAR(255),WHICHFILE varchar(255))
        --some variables
        declare @filename varchar(255),
                @path     varchar(255),
                @sql      varchar(8000),
                @cmd      varchar(1000),
    @lastrow  integer
        --get the list of files to process:
    SET @path = '\\chewbacca\PlantFloorData\RLData\'
        SET @cmd = 'dir ' + @path + '*.csv /b'
    print @path
    print @cmd
        INSERT INTO  ALLFILENAMES(WHICHFILE)
        EXEC Master..xp_cmdShell @cmd
        UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
        --cursor loop
        declare c1 cursor for SELECT WHICHPATH,WHICHFILE FROM ALLFILENAMES where WHICHFILE like '%.csv%'
        open c1
        fetch next from c1 into @path,@filename
        While @@fetch_status <> -1
          begin
      set @lastrow = 3 -- for now just to make sure logic below works
      print @lastrow
     --bulk insert won't take a variable name, so make a sql and execute it instead:
           set @sql = 'BULK INSERT HMIDATA.dbo.RawData FROM ''' + @path + @filename + ''' '
               + '     WITH ( 
                       FIELDTERMINATOR = '','', 
                       ROWTERMINATOR = ''\n'', 
                       FIRSTROW = 2 ,
       LASTROW = ' + STR(@lastrow) + '
        print @sql
        exec (@sql)
          fetch next from c1 into @path,@filename
          end
        close c1
        deallocate c1
        --Extras
        --delete from ALLFILENAMES where WHICHFILE is NULL
        --select * from ALLFILENAMES
        drop table ALLFILENAMES

    You could do a SELECT COUNT(*) FROM OPENROWSET(BULK), but you would need a format file that specifies a single-field record format with \r\n as the terminator. With the COUNT(*) you could determine the correct value for LASTROW.
    You could also load the entire file into a two-column table where one column is an IDENTITY column and the other is the raw data from the line in the file. And then you could crack the good rows.
    ...or you could write a client-side program or a SSIS package for the task.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Number of rows inserted is different in bulk insert using select statement

    I am facing a problem in bulk insert using SELECT statement.
    My sql statement is like below.
    strQuery :='INSERT INTO TAB3
    (SELECT t1.c1,t2.c2
    FROM TAB1 t1, TAB2 t2
    WHERE t1.c1 = t2.c1
    AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
    EXECUTE IMMEDIATE strQuery ;
    These SQL statements are inside a procedure. And this procedure is called from C#.
    The number of rows returned by the "SELECT" query is 70.
    On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
    But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
    And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
    On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
    Anybody faced these kind of issues?
    Can anyone tell what would be the reason of this issue..? any other work around for this...?
    I am using Oracle 10g R2 version.
    Edited by: user13339527 on Jun 29, 2010 3:55 AM
    Edited by: user13339527 on Jun 29, 2010 3:56 AM

    You have very likely concurrent transactions on the database:
    >
    By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
    >
    If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
    Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
    You can try to run your test with:
    set  transaction isolation level  serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
    like:
    wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46

  • Bulk Load question for an insert statement.

    I'm looking to put the following statement into a FORALL statement using BULK COLLLECT and I need some guidance.
    Am I going to be putting the SELECT statement into a cursor and then load the cursor values into a defined Nested Table type defined variable?
    INSERT INTO TEMP_ASSOC_CURRENT_WEEK_IDS
    SELECT aor.associate_office_record_id ,
    sched.get_assoc_sched_rotation_week(aor.associate_office_record_id, v_weekType.start_date) week_id
    FROM ASSOCIATE_OFFICE_RECORDS aor
    WHERE aor.OFFICE_ID = v_office_id
    AND (
    (aor.lt_assoc_stage_result_id in (4,8)
    AND v_officeWeekType.start_date >= trunc(aor.schedule_start_date)
    OR aor.lt_assoc_stage_result_id in (1, 2)
    ));

    I see people are reading this so for the insanely curious here's how I did it.
    Type AOR_REC is RECORD(
    associate_office_record_id dbms_sql.number_table,
    week_id dbms_sql.number_table); --RJS.***Setting up Type for use with Bulk Collect FORALL statements.
    v_a_rec AOR_REC; -- RJS. *** defining variable of defined Type to use with Bulk Collect FORALL statements.
    CURSOR cur_aor_ids -- RJS *** Cursor for BULK COLLECT.
    IS
    SELECT aor.associate_office_record_id associate_office_record_id,
    sched.get_assoc_sched_rotation_week(aor.associate_office_record_id, v_weekType.start_date) week_id
    FROM ASSOCIATE_OFFICE_RECORDS aor
    WHERE aor.OFFICE_ID = v_office_id
    AND (
    (aor.lt_assoc_stage_result_id in (4,8)
    AND v_officeWeekType.start_date >= trunc(aor.schedule_start_date)
    OR aor.lt_assoc_stage_result_id in (1, 2)
    FOR UPDATE NOWAIT;
    BEGIN
    BEGIN
    OPEN cur_aor_ids;
    LOOP
    FETCH cur_aor_ids BULK COLLECT into
    v_a_rec.associate_office_record_id, v_a_rec.week_id; --RJS. *** Bulk Load your cursor data into a buffer to do the Delete all at once.
    FORALL i IN 1..v_a_rec.associate_office_record_id.COUNT SAVE EXCEPTIONS
    INSERT INTO TEMP_ASSOC_CURRENT_WEEK_IDS
    (associate_office_record_id,week_id)
    VALUES
    (v_a_rec.associate_office_record_id(i), v_a_rec.week_id(i)); --RJS. *** Single FORALL BULK DELETE statement.
    EXIT WHEN cur_aor_ids%NOTFOUND;
    END LOOP;
    CLOSE cur_aor_ids;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('ERROR ENCOUNTERED IS SQLCODE = '|| SQLCODE ||' AND SQLERRM = ' || SQLERRM);
    dbms_output.put_line('Number of INSERT statements that
    failed: ' || SQL%BULK_EXCEPTIONS.COUNT);
    End;
    Easy right?

  • Parallel Insert statements (bulk) to the same table

    Hi,
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.
    Note that both will try to insert on the same table.
    Please let me know whether it is advisable or tell me an alternative way.
    Using...Oracle 11g DB.
    Regards
    Deep.

    935195 wrote:
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.Small number of rows. 50,000 rows can be inserted in seconds. Not sure why you want to split it. Parallel inserts into the same table is not usually a problem. Contention could be around free lists, initrans and so on - especially if using RAC and inserting something like 50,000+ rows every second. But the table defaults usually suffice.
    Note that both will try to insert on the same table.So what? This is exactly what Oracle expects and what it is designed to do.
    Please let me know whether it is advisable or tell me an alternative way.Well, you mentioned SQL worksheets - why? Exactly how does the INSERT statements look like? Where does the data to insert come from? Is shared insert cursors used (bind variables compulsory)? The bottleneck and problem could very well be on your side and not with the actual inserts into the table.

Maybe you are looking for

  • New MacBook Pro cannot connect to internet

    I've helped setup 2 MBP this week. Each of them could not connect to the wireless internet in my office using DHCP. In both cases I had to make a network setting of DHCP with manual address (I used 192.168.1.150 since my network is 192.168.1.x) and I

  • Cannot find PPoE host, can connect to router but not internet

    I've been having trouble since I tried using the router. At first, I had no security, then I set up the security and couldn't connect to the router. That finally solved, sometimes when trying to connect to the router, I get the message cannot find PP

  • "SYNC" Not listed in "SETTINGS"?

    Hello! I just purchased the ATV and get everything pretty well setup. I was able to sync my ITunes library to my ATV successfully by initiating a sync through my existing ITunes setup associated with my computer, where my catalog is housed. I then pu

  • Htp.p display

    htp.p(case when ucha>0 then '<span style="color:red;font-weight:bold"> '||ucha||'</span>''hh' when ucha<0 then '<span style="color:green;font-weight:bold"> '||ucha||'</span>' end); dislpay: 2633'hh I want result is 2633hh how can get ' off

  • Netweaver and Webflow

    I have experience with workflow and have started to look at the web enabling by use of Wf-RFC / SOAP messages. I wondered if this fits anyway into the NetWeaver overall strategy? I see some similarity with xApps and web enabled services, but never an