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

Similar Messages

  • Resukt:Get number of rows from 3 different table...?

    Hi All,
    I need to find out number of rows from 3 different table for the same conditions. Instead of writing 3 queries, is it possible to get it thru one query?
    For example, i need to find out number of rows in tables where name = 'Ameet' from 3 different table, i will end writing 3 queries.
    1. select count(1) from table_a where name = 'Ameet';
    1. select count(1) from table_b where name = 'Ameet';
    1. select count(1) from table_c where name = 'Ameet';
    Is it possible to write a single query to get result of all above 3 queries?
    result:
    table_a table_b table_c
    34 44 2

    One way:
    SELECT      (SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet') AS TABLE_A
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_B WHERE name='Ameet') AS TABLE_B
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_C WHERE name='Ameet') AS TABLE_C
    FROM DUALIf you want the total:
    SELECT     SUM(CNT)
    FROM
         SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_B WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_C WHERE name='Ameet'
    )

  • How to get the inserted row primary key with out  using select statement

    how to return the primary key of inserted row ,with out using select statement
    Edited by: 849614 on Apr 4, 2011 6:13 AM

    yes thanks to all ,who helped me .its working fine
    getGeneratedKeys
    String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
              String generatedColumns[] = {"DIPOFFERTEID"};
              PreparedStatement preparedStatement = null;
              try {
                   //String gen[] = {"DIPOFFERTEID"};
                   PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
                   pstmt.setLong(1, 1);
                   pstmt.executeUpdate();
                   ResultSet rs = pstmt.getGeneratedKeys();
                   rs.next();
    //               The generated order id
                   long orderId = rs.getLong(1);

  • Insert using select statement

    Hi,
    I am trying to insert values using select statement. But this is not working
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    VALUES
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;
    Please let me know what i am missing..
    Thanks
    Sudhir

    Try this
    INSERT INTO contribution_temp_upgrade
    (PRO_ID,
    OBJECT_NAME,
    DELIVERY_DATE,
    MODULE_NAME,
    INDUSTRY_CATERGORIZATION,
    ADVANTAGES,
    REUSE_DETAILS)
    SELECT
    :P1_PROJECTS,
    wwv_flow.g_f08(vRow),
    wwv_flow.g_f09(vRow),
    wwv_flow.g_f10(vRow),
    wwv_flow.g_f11(vRow),
    wwv_flow.g_f12(vRow),
    wwv_flow.g_f13(vRow)
    FROM DUAL;Note: when you are selecting a value using select statement, you should not specify the keyword "values".
    i assume you have already assigned value for your bind variable :P1_PROJECTS and rest of the functions will return some value.
    Regards,
    Prazy

  • Ignore first row of data file in bulk insert

    Hello
    I use bulk insert to fill a table
    I use code bellow
    bulk insert dbo.test
    from 'c:\test.txt'
    with(FIRSTROW=2,FORMATFILE='c:\test.xml'
    go
    but data inserted to table start from 3throw.
    Could you help me?

    I added that closing parenthesis.
    format file
    <?xml version="1.0"?>
    <BCPFORMAT
    xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
    <FIELD ID="1" xsi:type="CharFixed" LENGTH="6"/>
    <FIELD ID="2" xsi:type="CharFixed" LENGTH="2"/>
    <FIELD ID="3" xsi:type="CharFixed" LENGTH="6"/>
    <FIELD ID="4" xsi:type="CharFixed" LENGTH="13"/>
    <FIELD ID="5" xsi:type="CharFixed" LENGTH="13"/>
    <FIELD ID="6" xsi:type="CharTerm" TERMINATOR="\n"/>
    </RECORD>
    <ROW>
    <COLUMN SOURCE="4" NAME="R3" xsi:type="SQLBIGINT"/>
    <COLUMN SOURCE="5" NAME="R4" xsi:type="SQLBIGINT"/>
    <COLUMN SOURCE="1" NAME="R5" xsi:type="SQLVARYCHAR"/>
    <COLUMN SOURCE="3" NAME="R9" xsi:type="SQLVARYCHAR"/>
    <COLUMN SOURCE="2" NAME="R8" xsi:type="SQLVARYCHAR"/>
    </ROW>
    </BCPFORMAT>
    when I use firstrow=2 it works but do it from 3th row
    bulk insert dbo.test
    from 'c:\test.txt'
    with(FIRSTROW=2,FORMATFILE='c:\test.xml')
    go
    BUT when I use firstrow=1
    bulk insert dbo.test
    from 'c:\test.txt'
    with(FIRSTROW=1,FORMATFILE='c:\test.xml')
    go
    I get thia error
    bulk load data conversion  error(type mismatch or invalid character for the specified codepage)

  • How do I place an image and insert a different photo for the "mouse down" state?

    I have placed an image within an accordian widget and when I select the "mouse down" area in the states dialog box, i click "fill" in the toolbar and insert the photo i want to display when the image is clicked but this image is "covered up" by the originally placed image and is not seen in my states dialog box.
    I have done this before when i made rectangles and placed images in rectangles. But i soon realized that you cannot add alternative text to images in rectangles for some frustrating reason.
    How do I place and image and have a different image for the mouse down state?

    Hello,
    This effect can only be achieved when you use the images as a Rectangle Fill. And as you mentioned it above, you cannot add alternative text to images because it is added as a fill and not as a image.
    I would suggest you to post this as a feature request on our "Ideas for features in Adobe Muse" section of the forums : http://forums.adobe.com/community/muse/ideas
    Regards,
    Sachin

  • Insert into a table using select statement

    I have a table aa_table which alread has data for 3 columns now i need to insert
    the date for the 4th column C_id as shown below
    INSERT INTO aa_table s(s.c_id) values (select id from C_table c ,aa_table s
    where c.cin in( select s.cin from aa_table))
    Its says missing expression?
    Any one know what is wrong with this.
    Thanks

    yes this will update all the rows in the table
    UPDATE aa_table a
       SET c_id = (SELECT ID
                     FROM C_table c
                    WHERE c.cin = s.cin)this will update selected rows only
    UPDATE aa_table a
       SET c_id = (SELECT ID
                     FROM C_table c
                    WHERE c.cin = s.cin)
    WHERE EXISTS (SELECT 'c'
                     FROM C_table c
                    WHERE c.cin = s.cin)

  • How to insert an image file as blob using JDBC Statement

    Hi,
    I'm new on java.
    I want the code to insert an image file in Oracle database whose data type is blob.
    i want to use JDBC statement not the prepared statement.
    Please help me out.

    user8739226 wrote:
    thanks for the solution.
    I want to ask one thing
    let say i've created a method in a bean in which i'm passing three parameters.
    One is tablename as String, Second is Name of tablefields as Object, Third is Values as Object
    Like:
    public synchronized int insert(String table,Object[] fields, Object[] values)Ah now we're getting somewhere. I was trying to come up with a situation where using a regular Statement over PreparedStatement would be viable and came up with practically nothing.
    In the method body i'm accessing the table fields and values and combining them into the insert sql query.
    how can i do this using preparedstatment.
    how do i come to know here in this bean that this value is int or string or date at runtime to use setInt, setString, setdate or setBlob respectively.That's your problem. Bad design. You want to make some sort of universal insert method that can insert anything anywhere. But it doesn't really make sense, because whenever you're trying to insert something, you know exactly what you want to insert and where. You could use a PreparedStatement at that point (although encapsulate it in its own method). Now you're trying to create your own poorly designed framework over JDBC that doesn't solve problems, only increases them.
    Above was the only reason i saw, i was using statement instead of preparedstatment as statement was looking easy in this situation.
    please, give me the solution of above using preparedstatment.No, rather you should reconsider your design. What advantage does your insert() method give you over, let's say using a regular PreparedStatement. Granted, you can put your connection opening and other boilerplate code in the method. But if that's your only problem, then your insert method isn't gonna be much use. You could always switch to JPA for example and work with that.

  • How to insert variable value using select statement - Oracle function

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this.
    thanks

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
    Regards.

  • Number of records are different in database table and select statement

    Hi All,
    i need to fetch data from table BSID for the customer 0010000145
    if i am writing the code like -
        SELECT bukrs kunnr umskz shkzg dmbtr zfbdt zbd1t kkber
               FROM bsid
               INTO TABLE it_bsid
               FOR ALL ENTRIES IN it_kna1
               WHERE kunnr = it_kna1-kunnr
               and bukrs = pa_bukrs.
    no. of records are 130 in the internal table it_bsid
    and actual records are 200
    but when i am hardcoding the customer no.
    i am getting the exact records
       SELECT bukrs kunnr umskz shkzg dmbtr zfbdt zbd1t kkber
              FROM bsid
              INTO TABLE it_bsid
              FOR ALL ENTRIES IN it_kna1
              WHERE bukrs = pa_bukrs
                AND kunnr = '0010000145'.
    records in internal table = records in the database = 200.
    how it is possible.
    why the first code is not giving the correct no. of records.
    please reply asap.
    thanks in advance,
    madhu

    Madhu,
    You need to use the conversion routine...before u pass KUNNUR.
    CONVERSION_EXIT_ALPHA_RANGE_I
    CONVERSION_EXIT_ALPHA_RANGE_O
    Hope this helps..
    Chandra.

  • How to Display Number of Rows Deleted/Inserted etc... in PL/SQL

    In Oracle 10g PL/SQL, I have a delete statement in a stored procedure. It is not in a cursor. I want to see the number of rows I've deleted. I can use the dbms_output.put_line package. I should know this, but I don't have time to perfect the syntax. How would I get the number of rows that get deleted and display it via dbms_output.put_lline?

    No time to google either I guess.
    http://www.google.co.uk/search?q=number+of+rows+deleted+oracle&rls=com.microsoft:en-gb&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1&rlz=&redir_esc=&ei=Qi5qToGyGYqw8QOGzf3nAg
    SQL> create table dt_del_ex(id number);
    Table created.
    SQL> set serveroutput on
    SQL> BEGIN
      2
      3      INSERT INTO dt_del_ex VALUES(1);
      4
      5      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows inserted');
      6
      7      INSERT INTO dt_del_ex select rownum from dual connect by level <=10;
      8
      9      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows inserted');
    10
    11      UPDATE dt_del_ex SET id = id + 3 WHERE id >= 9;
    12
    13      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows updated');
    14
    15      DELETE FROM dt_del_ex WHERE id <= 10;
    16
    17      DBMS_OUTPUT.put_line(TO_CHAR(SQL%ROWCOUNT)||' rows deleted');
    18
    19  END;
    20  /
    1 rows inserted
    10 rows inserted
    2 rows updated
    9 rows deleted
    PL/SQL procedure successfully completed.

  • First Row Record is not inserted from CSV file while bulk insert in sql server

    Hi Everyone,
    I have a csv file that needs to be inserted in sql server. The csv file will be format will be like below.
    1,Mr,"x,y",4
    2,Mr,"a,b",5
    3,Ms,"v,b",6
    While Bulk insert it coniders the 2nd column as two values (comma separte) and makes two entries .So i used filelterminator.xml.  
    Now, the fields are entered into the column correctly. But now the problem is, the first row of the csv file is not reading in sql server. when i removed the  terminator,  i can get the all records. But i must use the above code terminator. If
    am using means, am not getting the first row record.
    Please suggests me some solution.
    Thanks,
    Selvam

    Hi,
    I have a csv file (comma(,) delimited) like this which is to be insert to sql server. The format of the file when open in notepad like below:
    Id,FirstName,LastName,FullName,Gender
    1,xx,yy,"xx,yy",M
    2,zz,cc,"zz,cc",F
    3,aa,vv,"aa,vv",F
    The below is the bulk insert query which is used for insert above records,
    EXEC(BULK INSERT EmployeeData FROM '''+@FilePath+'''WITH
    (formatfile=''d:\FieldTerminator.xml'',
    ROWTERMINATOR=''\n'',
    FIRSTROW=2)'
    Here, I have used format file for the "Fullname" which has comma(,) within the field. The format file is:
    The problem is , it skip the first record (1,xx,yy,"xx,yy",M) when i use the format file. When i remove the format file from the query, it takes all the records but the "fullName" field makes the problem because of comma(,) within the
    field. So i must use the format file to handle this. So please suggest me , why the first record skipped always when i use the above format file.
    If i give the "FirstRow=1" in bulk insert, it shows the "String or binary data would be truncated.
    The statement has been terminated." error. I have checked the datatype length.
    Please update me the solution.
    Regards,
    Selvam. M

  • Simple insert or bulk insert

    Hi,
    Hi have a problem regarding the bulk insert.
    I have 4 tables and each table has 16 partitions and each table near 2,00,000 records i am inserting
    Previously i tried bulk insert ..
    open insert_tab1;
    loop
    fetch insert_tab1 bulk collect into type_insert_tab1 limit 40000; --- fetch is near 2,00,000 records
    forall i in 1..type_insert_tab1.count
    insert into tab1 values type_insert_tab1(i);
    commit;
    exit when insert_tab1%notfound;
    end loop;
    Now similar insert i did for three other tables with the commit statementand in each table approx 2,00,000 records we are inserting.
    But i got snapshot too old error.how i can modify this to reduce commit and buffer use an dless execution time.
    or shall i take only insert into tab1
    (col1,
    col7)
    select *from tab2;
    Thanks in advance

    But i got snapshot too old error.how i can modify this to reduce commit and buffer use an dless execution time.You can reduce the number of commits by taking the commit out of the loop.
    It might be worth looking at the execution plan of the cursor in case it is less efficient than it could be.
    @ user11087632:
    Direct path insert uses fewer system resources, not more.
    The target table would need to be defined as NOLOGGING to get the full benefit; also indexes will affect direct path performance, and any foreign key constraints or row-level triggers will make it silently revert to conventional insert. And of course you lose the logging.
    Edited by: William Robertson on Jun 4, 2009 11:23 PM

  • Max number of rows?

    Hi,
    We have a new implementation of Enterprise X1 3.1 and are trying to determine what determines the maximum number of rows that can successfully be generated using Webi.  Is there a hard limit that Webi has (assuming the Universe max rows is deactivated)?
    Also, is there a limit for Live Office extractions into Excel?  What are the main drivers for this limit?
    Finally, all other factors being equal, are there different limits for the number of rows a query can return successfully in Webi vs Deski vs BEx?  How does the performance of these three tools compare to each other in terms of speed?
    Thanks!
    Darryl

    Thanks for your reply!  I also got a response back from SAP / BObj that I'll share:
    Q) We have a new implementation of Enterprise X1 3.1 and are trying to determine what determines the maximum number of rows that can successfully be generated using Webi. Is there a hard limit that Webi has (assuming the Universe max rows are deactivated)?
    => There is a limit to the number of pages Web Intelligence reports can have. This is because there are a maximum number of pages (per report) the server can process. This number depends on the paper size chosen. Generally, it is approximately 590000 inches vertically by 590000 inches horizontally. Therefore, if you choose a smaller paper size, you get more pages but may not see all the pages of the report.
    Resolution:
    To work around this behavior, you can either make each line smaller to get more records, or split your report into more than one report to see all your data.
    Q) Is there a limit for Live Office extractions into Excel? What are the main drivers for this limit?
    => By default its set to 512 rows and columns....however you can change this by modifying the Liveoffice_config.properties file...you can locate this file in /dswsbobje/lib/dsws_liveoffice_provider.jar.
    Q) Are there different limits for the number of rows a query can return successfully in Webi vs. Deski?
    => Although there is no official limit on the number of rows that can be handled by DeskI, it is really not meant to be used like a database, i.e. for returning millions of rows. The purpose of BusinessObjects reporting tools is to get useful information, which is not possible with millions of rows.
    => It has been observed that when the number of rows increases beyond 1.5 million approximately, it starts affecting the Desktop Intelligence performance. This behavior may vary from machine to machine depending upon the available resources and programs (processes) running in the background.
    => The limit is related to the number of rows those can actually be displayed in the report and not how many can be loaded into the data cube. All the rows get loaded in the cube however when it comes to rendering them in the report the problem may arise.
    Example: Report A returns 2 million rows into the cube however due to the report design there are only 200 rows in the actual report page and can be run successfully. Report B tries to render all 2 million rows into the actual report page and can fail.
    Workaround:
    Use filters in the report so that it will retrieve less number of rows and will also help to display useful data.

  • How to count the number of rows in a cube!!??

    Experts,
    I can somebody tell me how do I count the number of rows in my cube when i am using listcube???..
    Thanks
    Ashwin

    Hi,
    have a look ath this theard too
    Number of Records in Cube
    regards

Maybe you are looking for