Get the number of rows affected by update statement

I'm working on an application that uses OCI as interface against an Oracle database.
I'm trying to find out how i can get the number of rows affected by a query executed with OCIStmtExecute. it is not a select query.
Best regards,
Benny Tordrup

If I run a bulk UPDATE query using OCIBindArrayOfStruct, is there a way I can tell which+ rows successfully updated?
I have a file of records of which 75% of PKs are already in the table and will be updated, the other 25% aren't and should be inserted later. I want to attempt an UPDATE statement using OCIBindArrayOfStruct to execute in bulk and then check which entries in my bulk array successfully updated. If an array entry isn't successfully updated then I will assume it should be inserted and will store it for a Direct Path load later.
Many thanks for any advice you can give as I've been trawling through the docs trying to find a solution for ages now.

Similar Messages

  • How to get the number of rows in a ResultSet

    I'm an intern and I'm trying to get the number of rows from result set in oracle using rs.last() and rs.beforeFirst() methods
    but I got an error. Could Below is my sample code:
    import java.sql.*;
    public class SarueckConnect {
    public static void main(String[] args) {
    Connection con = null;
    Statement stmt = null;
    ResultSet re = null;
    String[] ParamArray;
    ParamArray = new String[24];
    //Properties logon;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver"); //Loading the Oracle Driver.
    con = DriverManager.getConnection
    ("jdbc:oracle:thin:@","data","data"); //making the connection DB.
    stmt = con.createStatement ();// Sending a query string to the database
    //stmt.executeUpdate("UPDATE test_table set steuk = 6 WHERE steuk = 5");
    ResultSet rs = stmt.executeQuery("SELECT mandt,kokrs,werks,arbpl,aufnr,vornr,ile01,"+
    "kostl,pernr,rueckid FROM test_table where steuk =6");
    //Print the result out.
    rs.last(); //This is the line which gives an error.
    int rows = rs.getRow();
    rs.beforeFirst();// I presume this is wrong to.
    ParamArray = new String[24*rows];
    int counter=0;
    while ( {
    for (int i = 1; i <= 24; i++){
    ParamArray[i-1+(counter*24)] = rs.getString(i);
    System.out.print(rs.getString(i) + '\t');
    } catch(Exception e) {
    } finally {
    if(stmt != null) stmt.close();
    if(con != null) con.close();
    } catch (Exception exception) {
    TryBapi sap = new TryBapi(ParamArray);
    }When I run the code I do have the following ERROR Message:
    java.sql.SQLException: Invalid operation for forward only resultset : last
    at oracle.jdbc.dbaccess.DBError.throwSqlException(
    at oracle.jdbc.dbaccess.DBError.throwSqlException(
    at oracle.jdbc.driver.BaseResultSet.last(
    at SarueckConnect.main( could any body Help me out here to figure out how to correct this?
    Any Help would be highly apprecited.

    make your result set scrollable...Not such a good idea. With Oracle, the JDBC driver will read and cache all the ResultSet in memory (with other DBMSs/drivers the behavior will probably be different, but you will still have some unnecessary overhead).
    You can do the caching yourself if you think it's worth it. If the piece of code you posted is why you need this for, then use a List or Vector and you won't need to know the size upfront.
    The jTDS Project.

  • How to count the number of Rows to be Updated before Update takes place..

    Hi all,
    I have a requirement, where i have to count the number of rows to be updated before updating it. SQL%ROWCOUNT gives the no. of rows updated ( after update takes place). How do i get to know the count of no. of rows to be updated/inserted/ deleted. I was looking for a simple solution, as above SQL%Rowcount. But i couldn't find any. I can use a Function and Return the value which will give me number of rows to be updated, But is there any Simple Logic other than this.. or any count function. Your Help is Appreciated. Thanks!

    If you really want to do this (I have no clue why you would need it), then you can piggy back on any existing pessimistic locking you may already have in place.
    However, it would require two loops through the records of which you want to know the count before you update, and a second pass to update them.
    I would really re-think the need for this, though.
    SQL> create table t0304(c number);
    Table created.
    SQL> insert into t0304 select rownum from all_objects where rownum <= 10;
    10 rows created.
    SQL> commit;
    Commit complete.
    SQL> select * from t0304;
    10 rows selected.
    SQL> declare
      2    cursor mycursor is select * from t0304 where mod(c,2) = 0 for update;
      3    i number := 0;
      4  begin
      5    for r in mycursor loop
      6      i := i + 1;
      7    end loop;
      8    dbms_output.put_line(i);
      9    for r in mycursor loop
    10      update t0304 set c = c + 20 where current of mycursor;
    11    end loop;
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SQL> commit;
    Commit complete.
    SQL> select * from t0304;
    10 rows selected.
    SQL>Edited by: Steve Howard on Mar 4, 2011 5:57 PM

  • How to get the number of rows in a repeating frame ?

    Hi all,
    When I launch a report from forms then sometimes there are data in the report and sometimes there are no data. And the problem is that when there are no data then the frame containing the repeating frame is still displaying and a blank page displays on the report.
    So I want to get the number of rows from the repeating frame so that I can code a format trigger on the frame to display or not the enclosing frame depending on the existence of data from the repeating frame.
    Thank you very much indeed.

    Dear Friend,
    You can achieve this. Define a summary column (say cnt). Select summary type as "COUNT". select any one of columns that are getting displayed in your repeating frame as summary column and provide "reset at" group name (or set this to report if you are defining this field at report level) . This "cnt" variable will contain how many records that will be fetched for your repeating frame (i.e. Group of Repeating frame). You can use this "CNT" variable in your format trigger.
    In this case there is no need to write before report trigger or anything.
    Manish Trivedi

  • How to get the number of rows in a DB-Cursor

    When i open a database cursor i do not know how much rows are stored in the cursor. To solve this problem i have to send a 'select count(1) ...' to get the number of rows before i set up the cursor. I think that this is not very clever and could possibly cause performance problems. But i need the num of rows to show the percentage of processed rows. Is there any other way to get the num of rows? May be by checking the cursor directly?
    Please help!
    Thanx a lot

    In order to find out how may rows are going to be processed, oracle has to visit every row. So with a cursor, there is no property that will accurately reflect the number of rows until you get to the last one. That said, you could use
    select count(*) over() as row_count, <rest of your columns> FROM <your table>
    which will give you the total row count agaist each row in the result set. There are performance penalties involved but they will be less than issuing the query twice, once to get the count and once to get the rows.
    Have a look on asktom for some very usefull info about all this.

  • How to get the number of rows in a report region

    Hi all,
    Is there a way to get the number of rows returned in a report region, without issuing an additional "select count(*) from some_table"?
    I mean something like the substitution string #ROW_NUM# but for the total rows.
    For classic report regions, the region footer supports the following substitution strings:#ROWS_FETCHED# shows the number of rows fetched by the Oracle Application Express reporting engine (the page size). You can use these substitution strings to display customized messages to the user. For example:
    Fetched #ROWS_FETCHED# rows in #TIMING# seconds.
    *#TOTAL_ROWS# displays the total number of rows that satisfy a SQL query used for a report.*
    #FIRST_ROW_FETCHED# and #LAST_ROW_FETCHED# display the range of rows displayed. For example:
    Row(s) #FIRST_ROW_FETCHED# through #LAST_ROW_FETCHED# of #ROWS_FETCHED# displayed>

  • How to get the number of rows written to the header of the spool file.

    I need to create a header line for the spool file .
    the header line should include fixed length values .
    The header should include the number of records found in the table with a maximum begin date (begin_date is the column of the table)
    To get the header in the spool file , i wrote a select query has :-
    --SPOOL 'C:\Documents and Settings\abc\Desktop\output.TXT'
    select 'W'||to_char(sysdate,'MM/DD/YYYYMi:HH:SS')||lpad(max(rownum),9,'000000000') ||'R'||max(to_char(school_from_date,'MM/DD/YYYY')) ||
    rpad(' ',76,' ')
    group by sysdate;
    which gets me all the rows in the table , but i only want the rows with the latest school_begin_date .
    how can i achieve that ...
    I know that a subquery should be written in the from clause to get the number of rows found with a maximum school_begin_date.
    select 'W'||to_char(sysdate,'MM/DD/YYYYMi:HH:SS')||lpad(max(rownum),9,'000000000') ||'R'||max(to_char(school_from_date,'MM/DD/YYYY')) ||
    rpad(' ',76,' ')
    from where
    select rownum from
    where school_begin_date = max(school_begin_date) ;
    the error i get is
    ORA-00934: group function is not allowed here

    Try this:
    select 'W'||to_char(sysdate,'MM/DD/YYYYMi:HH:SS')||lpad(max(rownum),9,'000000000')||'R'||max(to_char(school_from_date,'MM/DD/YYYY')) || rpad(' ',76,' ')
    where school_begin_date = (select max(school_begin_date)

  • How can I get the number of rows in my sql result, without a loop?

    I've a problem, I would like to get the number of rows in my sql result without make a loop like :
    while ({
    int number = rs.getRow();
    Is there any method to do this, on the first element?
    Thx, STeF

    If you want to count how many rows are in result set, I dont think you can, but you could always run a count statement for that sql
    say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......
    then you can count the rows this statement returns by
    select count(*) from
    (say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......)
    This way you will get the count for just that sql

  • Getting the number of rows returned from ResultSet

    Does anyone know a method to get the number of rows returned with a query using the Resultset class?

    Hi 281080,
    If your database and JDBC driver support it, in order to use the solution that da-alexj has suggested, you need to create a 'scrollable' "ResultSet" -- the javadoc for method "createStatement()" (in class "java.sql.Connection") has more details.
    However, I have found with Oracle database and Oracle (thin) JDBC driver, that part of their implementation of the "last()" method (in class "java.sql.ResultSet") is to actually iterate through the entire "ResultSet" in order to reach the last row. If your "ResultSet" is very large (I tested it with a 100,000 row "ResultSet"), this will take a long time.
    Just wanted to make you aware of that.
    Of-course, this may be irrelevant to you since I didn't see any mention in your post of what database and JDBC driver you are using.
    Hope this has helped you, anyway.
    Good Luck,

  • How to get the number of rows returned by a report?

    I'm developing my first application in APEX and so far everything seems fine, except I can't figure out this very simple thing: I have a report based on a PL/SQL block returning an SQL string. I'd like to have a message (something like "X rows returned") just before the report. The closest thing I could find was "X to Y out of Z" in the pagination styles, but that's not what I want. Also I don't think running the same query to get COUNT() is wise.
    Any help would be appreciated.

    My guess is that it only shows the number of rows it has retrieved. I believe the defailt is for it to only retrieve 50 rows and as you page through your report it retrieves more. So this would just tell you how many rows was retireved, but probably not how many rows the report would contain if you pages to the end. Oracle doesn't really have a notion of total number of rows until the whole result set has been materialized.

  • Urgent******how can i get the number of rows enterd by the user in a table

    Hi Frndz..
    As per my requirement i need to do the validations for the multipple rows in a table that was enterd by the user,
              The prob is how can i get that number of rows that enterd by user,
           WDMessageManager msg = wdComponentAPI.getMessageManager();
         String col1= "";
         String col2= "";
         double col3= 0;
         double col4= 0;
         double amount= 0;
         int nodesize = wdContext.nodeTest().size();
         for(int i=0; i<=2 ; i++)
                   col1 = wdContext.nodeTest().getTestElementAt(i).getCol1();
                 //msg.reportSuccess("col1 size is :"+col1);
                   col2 = wdContext.nodeTest().getTestElementAt(i).getCol2();
                   col3 = wdContext.nodeTest().getTestElementAt(i).getCol3();
                   col4 = wdContext.nodeTest().getTestElementAt(i).getCol4();
                    amount = wdContext.nodeTest().getTestElementAt(i).getAmount();
              if(col1 == "" )
                        msg.reportException("Plz fil the col1 for line:",true);
              if(col2 == "" )
                                  msg.reportException("Plz fil the col2 for line:",true);
              if(col3 <= 0)
                   msg.reportException("Plz fil the col3:",true);
                   if(col4 <= 0)
                   msg.reportException("Plz fil the col4:",true);
         catch (Exception e)
                   msg.reportException("strMessage in catch block",true);
         this is the code am going

       You can try this:
    * Let's say the table's datasource is a node called Table  and it has two attributes first & second.
    * You want to check if any of these attributes has been changed by the user or not. If they have been
    * changed then you want to do some validations against them.
      int sizeOfTable = wdContext.nodeTable().size();
      for(int i = 0; i < sizeOfTable; i++){
         IPrivate<view name>.ITableElement ele = wdContext.nodeTable().getTableElementAt(i);
         if(ele.isChangedByClient(ITableElement.<attribute name>)){
            //value has been changed, do some validation. You can get the row index using ele.index().

  • How do I get the number of rows in a ResultSet?

    I checked the API, but didn't find a method that does this.

    You could try calling last() then getRow() to get the
    no of rows ...You probably need a scrollable resultset to do this, so that you can
    rewind back to the start and read the data in.
    I imagine you want to get a count, to size an array, before reading in the data ? Why not load it in an arraylist, then convert to an array afterwards ?

  • Get the number of rows returned by a dataProvider

    I am using a [Bindable] variable that I am setting and using
    as a DataProvider (coming from a web service) for a DataGrid within
    my Flex 2 application.
    is there a way of knowing the amount of rows that the
    dataProvider is returning???
    as I want to do a calculation to set the height of the
    dataGrid depending on the amount of rows being returned by the
    any suggestions...?

    that only seems to count the default number of rows (height)
    of the datagrid..... i.e. 7.
    I need to know the number of rows being returned from the
    dataProvider - i.e. the number of rows coming through the
    webService from the database etc.....

  • Get the number of rows in a cursor?

    Currently I have a pretty simple stored procedure that builds some dynamic SQL then returns those results to some code.
    I would like also to be able to return the number of rows in that cursor back to the Java code, how can I do this? Some sample SQL is shown below:
    l_query := 'Select * from customer';
    OPEN searchResults FOR l_query;
    ???? Select count(*) into totalResults from searchResults; ????
    (^^This last row is the issue)
    I need to return the varaible totalResults as the count
    Thanks heaps!!

    If I understand you correctly, what you desire cannot be done.
    When Oracle opens a cursor, it doesn't know how many rows that cursor will return.
    The only two options is either do a separate query to count the number of rows that the original query will return, or fetch all the rows and see how many you got.
    I recall seeing an example of that in the JDBC sample code on the OTN Web site.
    (But I'm too lazy to look for it for you.)
    Good Luck,

  • How do i get the number of rows in Resultset?

    Is there a way to make the size of string array according to the number of records
    from the Resultset? The other problem is the values in saRow are all null.Why is it so? Thanks for helping me in advance
    String sql = "SELECT Name FROM UserType" ; << Return "Admin" "User" "CIO"
    ResultSet rs = db.ExecuteSQL(sql);
         while ( {
         int i=0,rowCount;
         String[] saRow = new String[2]; << supposed to use rowCount
         saRow[i++] = rs.getString("Name");
    Database Query Success
    null << saRow value

    Essentially, you can't. A ResultSet is not a set of rows in memory: it is a cponnection to a back end database. Potentially, you start getting results out of the result set while the database is still searching for more.
    I see this all the time on these forums: people doing work in java that is better done on the database. If you want to know the number of records in the database, ask the database: "select count(*) from UserType". Especially once you start needing to search big tables.
    However, in this case, where you are just loading up the types: why bother? You know that there wioll only be a few of them. Load the results into an ArrayList. Go to the JavaDocs that you downloaded with the JDK, go to the "guides" section, and see the guide on the collections API.

Maybe you are looking for

  • Change Doc title in Tcode sost when emailing quotation doc

    Hi, Currently, After emailing a quotation, I go to tcode SOST to check the status of the email. I saw that: the "Doc title" of the email is: Program name/Date/time. I want to change the "Doc title" to a new value. Could you please help me with this i

  • SCSI drive recognition

    I recently added drives to my G4 and moved the PCI SCSI card to a new slot. After rebooting the system now registers my 40G SCSI drive as new hardware and I cant seem to figure out how to save the info on the disk. I even moved it back to the origina

  • Include in ABAP class for Workflow

    Hi, In order to use BOR macros inside ABAP class, (From SAP help) came to know that we need to use include <cntn02> . How to add this include to ABAP class for workflow? Regds, Akshay

  • Issue in starting local J2EE server

    Hello, I am trying to start my Developer Workplace Local J2EE server ....but get the following message on doing that: sapstartsrv.exe has encountered a problem and needs to close. We are sorry for the inconvenience.... Please help.

  • Capture auto generating seqs

    Hi, Is there a way with FCP to auto create sequences during DV capture based on the timestamp of the clips on the tape? I mean one sequence per take. Thanks, fred.   Mac OS X (10.4.3)