ROWID in update statment

Hi all,
Please advice if following statment will update correct rows?:
for x in (select rowid from table where col=345 and col2=567 and col3=678)
loop
update table set col6=344 wher rowid=x.rowid;
end loop;
I just whant to be sure that refference to rowid column in update statment will update correct rows.
Is the any cases when rowid value can be changed between fetching and updating?
Thank you.

You probably should make sure that you aren't updatind a record that has already been updated by checking that col6 <> 344 in both the guard at the beginning of the loop and in the update statement folowing the guard.
LOOP
  -- check if still rows to update
  begin
     select 'x'
     into v_dummy
     from table
     where col1=345 and col2=567 and col3=678 and col6 <> 344
     and rownum = 1;
  exception
     when no_data_found then
        exit; -- leave loop
  end;
  update table
  set col6=344
  where col1=345 and col2=567 and col3=678 and col6 <> 344
  and rownum <= 50000; -- use big chucks to update
  commit;
END LOOP;

Similar Messages

  • Problem in update statment when using where condtion

    Hi ,
          Iam using update statment to update field in Z-Table .My statment is not working fine as per my requirement.The statment is as below,
    UPDATE ZFINAL_DATA  SET ZDATE_FLAG = SPACE where ZGLOBAL_CODE ( SELECT LIFNR FROM LFA1 WHERE KTOKK = 'ZLIE' ).
    But this statment is doing my purpose .
    My requirement is , I need to update ZDATE_FLAG = SPACE in ZFINAL_DATA table when LFA1 -LIFNR = ZFINAL_DATA-ZGLOBAL_CODE and LFA1-KTOKK = 'ZLIE'.
    Can any correct the update statment which will be helpfull to proceed further .
    Regards,
    Sriram

    Hi Sriram,
    Have a look into the logic of the below query. Maybe this will fulfil the requirement.
    TYPES:     BEGIN OF lt_lifnr,
             lifnr TYPE lifnr,
         END OF lt_lifnr.
    DATA:      la_lifnr TYPE TABLE OF lt_lifnr,
           wa_zfinal_data TYPE zfinal_data,
           la_zfinal_data TYPE TABLE OF zfinal_data.
    TABLES: zfinal_data.
    SELECT lifnr
    FROM lfa1
    INTO TABLE la_lifnr
    WHERE ktokk = 'ZLIE'.
    SORT la_lifnr BY lifnr.
    SELECT *
    FROM zfinal_data
    INTO TABLE la_zfinal_data.
    LOOP AT la_zfinal_data INTO wa_zfinal_data.
      READ TABLE la_lifnr WITH KEY lifnr = wa_zfinal_data-zglobal_code
                          BINARY SEARCH TRANSPORTING NO FIELDS.
      IF sy-subrc = 0.
        wa_zfinal_data-zdate_flag = space.
        MODIFY la_zfinal_data
        FROM wa_zfinal_data
        INDEX sy-tabix
        TRANSPORTING zdate_flag.
      ENDIF.
    ENDLOOP.
    MODIFY zfinal_data FROM TABLE la_zfinal_data.
    COMMIT WORK.

  • UPDATE statment

    hi for all, plz i have a question ,i have a tabel called (ClientT) which contain these fielde
    First_Name
    Last_Name
    UserID
    Address
    Password
    BirthDate
    Answer
    and i need to make an Update to this table according to some informatio ,My Code
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              String url = "jdbc:odbc:test";
            // Step 2: Establish the connection to the database.
              java.sql.Connection c = DriverManager.getConnection(url,"", "");
              java.sql.Statement st = c.createStatement(); 
              String Query = "UPDATE ClientT " +
                             "SET Password = 'pass' "+
                             "WHERE (Address LIKE 'city') AND (BirthDate LIKE 'birth') AND (Answer LIKE 'color')";
              st.executeQuery(Query);        
             st.close();
             c.close();
         catch(SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());
         catch(ClassNotFoundException ex) {
             System.out.println("Class Not Found Exception ");               
              }when the trace reach
    String Query = "UPDATE ClientT"+
    it jump to th st.close();
    what is the problem, the problem is with the UPDATE SQL Query.is the structure of this query correct??
    Thanks.

    thank you for your third point i make it but still the code not done what i need (update the password in the tabel according to certain Client information),
    i dont have an error to do
    exception.printStacktrace();
    the code not produce an error through debugging,or through run,so i thing the UPDATE statment not coorect.
    i use this UPDATE statment for the first time so i dont sure is the structure of it right or not, and i using NetBeens IDE.
    can you help me or give me an examples of UPDATE Statment.
    thank
    i have a question< is there is a diffrence when i replace the LIKE whith = in my SQL query?
    my final code is
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              String url = "jdbc:odbc:test";
            // Step 2: Establish the connection to the database.
              java.sql.Connection c = DriverManager.getConnection(url,"", "");
              java.sql.Statement st = c.createStatement(); 
              String Query = "UPDATE ClientT " +
                                    "SET Password = ('"+pass+"') "+
                                    "WHERE (Address = 'city') AND (BirthDate = 'birth') AND (Answer = 'color')";
              st.executeUpdate(Query);        
             st.close();
             c.close();
         catch(SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());
         catch(ClassNotFoundException ex) {
             System.out.println("Class Not Found Exception ");               
              }Edited by: master2007 on Mar 16, 2008 1:13 AM

  • One Update Statment

    Hi ,
    I wana use two column conditionally in an update statement rather then writing two statement for each conditions.
      update war_room_report_aged
         set case when p_business_days_old=15 then nrpc_15_days
                  when p_business_days_old=25 then nrpc_25_days
                  when p_business_days_old=10 then nrpc_10_days end  = exceeds_sr.c_date_recd
       where bus_unit_abbrev = exceeds_sr.abr_bus_unit||'_'||exceeds_sr.abr_sub
         and todays_date     = p_end_date
         and tio_priority    = p_level;I can do it with two statement seperatly ,but i got in a situation where there would be more than 5 columns need to be updated according to parameter's value.
    if p_business_days_old=15 then
    update war_room_report_aged
         set  nrpc_15_days=exceeds_sr.c_date_recd
       where bus_unit_abbrev = exceeds_sr.abr_bus_unit||'_'||exceeds_sr.abr_sub
         and todays_date     = p_end_date
         and tio_priority    = p_level;
    elsif p_business_days_old=25 then
    update war_room_report_aged
         set  nrpc_25_days=exceeds_sr.c_date_recd
       where bus_unit_abbrev = exceeds_sr.abr_bus_unit||'_'||exceeds_sr.abr_sub
         and todays_date     = p_end_date
         and tio_priority    = p_level;
    elsif .. then
    end if;Can i made the same above in one statment?I am so devastated as there gonna be more than 10 conditions for 10 parameter and for each parameter's value relate to seperate 10 cloumns.

    You can do it this way:
    create table test_table
    pk_col     number,
    cond_1     number,
    col_1      varchar2(5),
    cond_2     number,
    col_2      varchar2(5),
    cond_3     number,
    col_3      varchar2(5)
    insert into test_Table values (1, 10, 'AAA', 20, 'BBB', 30, 'CCC');
    update test_table
       set col_1 = decode(&input, 10, col_1 || '1', col_1),
           col_2 = decode(&input, 20, col_2 || '1', col_2),
           col_3 = decode(&input, 30, col_3 || '1', col_3)
    where pk_col = 1;
    select *
      from test_table;
    PK_COL                 COND_1                 COL_1 COND_2                 COL_2 COND_3                 COL_3
    1                      10                     AAA1  20                     BBB   30                     CCCLogic is to check if the variable matches a certain Input condition, then update the column with new value, else just update it with Itself. This way, you achieve it in a single SQL and still do not risk losing column information.

  • How to use the Output clause for the updated statment

    How to use the output clause for the below update stament,
    DECLARE @MyTableVar table(
        sname int NOT NULL)
    update A set stat ='USED' 
    from (select top 1 * from #A 
    where stat='AVAILABLE' order by sno)A
    Output inserted.sname
    INTO @MyTableVar;
    SELECT sname
    FROM @MyTableVar;
    Here am getting one error incorrect syntax near Output
    i want to return the updated value from output clause

    see
    http://blogs.msdn.com/b/sqltips/archive/2005/06/13/output-clause.aspx
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Using a WITH list in an update statment

    I have the following SQL that gives a 'The multi-part identifier "CurrentScannedCasks.CSC" could not be bound.' error,.
    So how can I, or can I, use the contents if a WITH statement to populate this update statement?
    WITH CurrentScannedCasks (CSC) AS (
    select CaskNo
    from AllocationCask ac
    inner join allocation a on a.ID = ac.AllocationID
    where a.AllocationNo = 143601 -- {allocation number from input}
    and ac.CaskScanned =1
    and ac.AllocationID = (select distinct top 1 allocationID as latestAllocationID
    from AllocationCask ac
    inner join allocation a on a.ID = ac.AllocationID
    where a.AllocationNo = 143601
    order by allocationID DESC)
    update scantransaction
    set AllocationCaskID = (select ID from AllocationCask
    where caskNo = CurrentScannedCasks.CSC
    and AllocationID = (select distinct top 1 allocationID as latestAllocationID
    from AllocationCask ac
    inner join allocation a on a.ID = ac.AllocationID
    where a.AllocationNo = 143601
    order by allocationID DESC))
    Where ID = (select top 1 ID from scantransaction st
    where SUBSTRING(st.CaskBarcode, 13, 7) = CurrentScannedCasks.CSC
    and st.AllocationNo = 143601
    order by ID DESC)

    I forgot the from!
    e.g.
    WITH CurrentScannedCasks (CSC) AS (
    select CaskNo
    from AllocationCask ac
    inner join allocation a on a.ID = ac.AllocationID
    where a.AllocationNo = 143601 -- {allocation number from input}
    and ac.CaskScanned =1
    and ac.AllocationID = (select distinct top 1 allocationID as latestAllocationID
    from AllocationCask ac
    inner join allocation a on a.ID = ac.AllocationID
    where a.AllocationNo = 143601
    order by allocationID DESC)
    update scantransaction
    set AllocationCaskID = (select ID from AllocationCask
    where caskNo = CurrentScannedCasks.CSC
    and AllocationID = (select distinct top 1 allocationID as latestAllocationID
    from AllocationCask ac
    inner join allocation a on a.ID = ac.AllocationID
    where a.AllocationNo = 143601
    order by allocationID DESC))
    from CurrentScannedCasks
    Where ID = (select top 1 ID from scantransaction st
    where SUBSTRING(st.CaskBarcode, 13, 7) = CurrentScannedCasks.CSC
    and st.AllocationNo = 143601
    order by ID DESC)
    But it still dosn't appear toi be working properly, It should update all the caskScanned fields of the current allocation to 1 where any previous version of the cask was 1.
    Then update the current allocationCaskId of the relevant transactions table record to that of the latest version od the cask record in the allocation cask table.
    It looks like this isn't quite doing what I expected!

  • JDBC adapter update statment

    Hello All,
    In my sender jdbc adpter configuration i read data from table that contains filed 'status' witch indicate does record has been send to sap. But limitation of this solution is that i read up to ne row and example query looks like this
    select up to 1 rows * from table where status = 0 order by id.
    and update query
    update table set status = 1 where id = ( select id 1 rows * from table where status = 0 order by id )
    Can you write your strategy of reading multiple records.
    I know that stored procedure can be solution of this problem, but i'm wondering how do you handle with that.
    BR
    Maciej

    you can indeed read and update multiple records;
    Adapter Work Method
    ·        You must add an indicator that specifies the processing status of each data record in the adapter (data record processed/data record not processed) to the database table.
    ·        The UPDATE statement must alter exactly those data records that have been selected by the SELECT statement. You can ensure this is the case by using an identical WHERE clause. (See Processing Parameters, SQL Statement for Query, and SQL Statement for Update below).
    ·        Processing can only be performed correctly when the isolation level for transaction is set to repeatable_read or serializable.
    Example
    SQL statement for query: SELECT * FROM table WHERE processed = 0;
    SQL statement for update: UPDATE table SET processed = 1 WHERE processed = 0;
    processed is the indicator in the database.
    the above is from SAP help.
    follow the query as mentioned and do not forget to set the repeatable_read or serializable in the adapter
    http://help.sap.com/saphelp_nw04/helpdata/EN/7e/5df96381ec72468a00815dd80f8b63/frameset.htm

  • Need to reduce no of calling same  function  in update statment

      update tab1 set
        col1  =  FN1(a),
        col2  =  FN2(a),
        col3  =  FN3( FN1(a), FN2(a) , c )
    here  FN1 and FN2 is called two time .. or only once ,, ??
    if 2 time then how to make it once call only ...
    can we change it like this
         update tab1 set
        col1  =  FN1(a),
        col2  =  FN2(a),
        col3  =  FN3( col1  , col2   , c )
    both r same or differnt ..??Edited by: user12108669 on Dec 11, 2009 4:31 AM

    Hi,
    Those are very good questions.
    Riedelme has told you who is the best person to answer thiose questions: you.
    To see how ofte a function is called, you can have it display something (using dmbs_output) or increment a sequence, package variable or SYS_CONTEXT attribute.
    CREATE TABLE tab1
    (        a      NUMBER
    ,        col1    NUMBER
    ,            col2      NUMBER
    ,      col3      NUMBER
    ,      c      NUMBER
    INSERT INTO tab1 (a) VALUES (1);
    INSERT INTO tab1 (a) VALUES (2);
    INSERT INTO tab1 (a) VALUES (3);
    CREATE SEQUENCE      fn1_seq    START WITH 1;
    CREATE SEQUENCE      fn2_seq    START WITH 1001;
    CREATE OR REPLACE FUNCTION      fn1
    (      in_num       IN        NUMBER
    RETURN NUMBER
    IS
         seq_val     NUMBER;
    BEGIN
         SELECT  fn1_seq.NEXTVAL
         INTO     seq_val
         FROM     dual;
         RETURN     seq_val;
    END     fn1;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION     fn2
    (      in_num       IN        NUMBER
    RETURN NUMBER
    IS
         seq_val     NUMBER;
    BEGIN
         SELECT  fn2_seq.NEXTVAL
         INTO     seq_val
         FROM     dual;
         RETURN     seq_val;
    END     fn2;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION     fn3
    (      in_x       NUMBER
    ,      in_y       NUMBER
    ,      in_z       NUMBER
    RETURN     NUMBER
    IS
    BEGIN
         RETURN  in_x + in_y;
    END     fn3;
    SHOW ERRORSTo avoid calling the functions repeatedly, you can use MERGE instead of UPDATE, like this:
    MERGE INTO  tab1    dst
    USING  (
           SELECT  a
           ,       fn1 (a)     AS fn1_a
           ,       fn2 (1)     AS fn2_a
           ,       c
           FROM    tab1
           )         src
    ON     (src.a         = dst.a)
    WHEN MATCHED THEN UPDATE
    SET  dst.col1       = src.fn1_a
    ,    dst.col2       = src.fn2_a
    ,    dst.col3       = fn3 (src.fn1_a, src.fn2_a, src.c)
    SELECT       *
    FROM       tab1
    ORDER BY  a;Output:
    .        A       COL1       COL2       COL3          C
             1          1       1001       1002
             2          2       1002       1004
             3          3       1003       1006

  • Update statment problem

    I having a problem using th following preparded statement:
    String updateDatabase = "UPDATE titles SET titles.isbn = ? WHERE titles.isbn = "+ISBN+"";//ISBN is a string already initialized
    preStatement = connection.prepareStatement(updateDatabase);
    preStatement.set.setString(1,Sisbn);//Sisbn is a string to update database.
    preStatement.executeUpdate();
    preStatement.close();
    This of course is inclosed in a try catch.
    However, when I run this I get the following error:
    Data type mismatch in criteria expression.
    The field in the database is text so I don't see what could be the mismatch. Any help would be appreciated.

    1) You didn't quote the value in the where clause
    2) Why can't you use another parameter (?) and set that, too? Example from the docs:PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
                                         SET SALARY = ? WHERE ID = ?");

  • Help with UPDATE statment

    Hello,
    i have a table like this:
    create table test
    (id number,
    stat number,
    id_num number);data in table:
    insert into table test (id,stat,id_num) values (1,112,'');
    insert into table test (id,stat,id_num) values (1,123,'');
    insert into table test (id,stat,id_num) values (2,134,'');
    insert into table test (id,stat,id_num) values (2,111,'');
    insert into table test (id,stat,id_num) values (3,112,'');
    insert into table test (id,stat,id_num) values (4,111,'');
    insert into table test (id,stat,id_num) values (4,12,'');
    insert into table test (id,stat,id_num) values (4,11,'');I want to update column id_num with sequence number under same ID.
    Below is the table with correctly updated coloumn.
    insert into table test (id,stat,id_num) values (1,112,1);
    insert into table test (id,stat,id_num) values (1,123,2);
    insert into table test (id,stat,id_num) values (2,134,1);
    insert into table test (id,stat,id_num) values (2,111,2);
    insert into table test (id,stat,id_num) values (3,112,1);
    insert into table test (id,stat,id_num) values (4,111,1);
    insert into table test (id,stat,id_num) values (4,12,2);
    insert into table test (id,stat,id_num) values (4,11,3);Can someone give me a hint how to pull this off?
    Thank you for your help!

    Hi,
    what is the order of assigning the sequence within the same id?
    You cannot rely on the order of row number as Oracle does not ensure that it is giving back the rows in the sequence in which they have been inserted.
    I have assumed here that within the id the id_num is numbered ordered by stat:
    MERGE INTO test a
         USING (SELECT id, stat
                     , ROW_NUMBER () OVER (PARTITION BY id ORDER BY stat) AS val
                  FROM test) b
            ON (a.id = b.id AND a.stat = b.stat)
    WHEN MATCHED
    THEN
       UPDATE SET id_num = val;
    SELECT *
      FROM test
    ORDER BY id, stat;
            ID       STAT     ID_NUM
             1        112          1
             1        123          2
             2        111          1
             2        134          2
             3        112          1
             4         11          1
             4         12          2
             4        111          3Regards.
    Al

  • Doubt on update Statment

    Removed
    Message was edited by:
    MIND

    Like this ?
    WHERE (    LICNXX.PRPR_ID = AFRSXX.SRV_PRPR_ID
           AND LICNXX.LICN_STATE = AFRSXX.SRV_PRAD_STATE
           AND LICNXX.PRPR_TYPE ='F'
           AND AFRSXX.CLCL_CL_SUB_TYPE ='I')
    OR    (    LICNXX.PRPR_ID = AFRSXX.PRCP_ID
           AND LICNXX.LICN_STATE = AFRSXX.SRV_PRAD_STATE
           AND LICNXX.PRPR_TYPE ='C'
           AND AFRSXX.CLCL_CL_SUB_TYPE ='P')
    AND ROWNUM = 1Nicolas.

  • Update using rowID - 9i

    hi everyone,
    i´m updating a table that has more then ten miilion records, but don´t have PK... and this is very time consuming...
    Anyone have any idea how to improve this?
    Tks
    update tablex
    set a = :a
    ,b= :b
    where rowiId = :rowId
    above the trace:
    UPDATE CRH_CONTRACHEQUE SET FL_MIGRADO = 'S' ,CDHISTORICORUBRICAVINCULO = :B2
    WHERE
    ROWID = :B1
    UPDATE CRH_CONTRACHEQUE SET FL_MIGRADO = 'S' ,CDHISTORICORUBRICAVINCULO = :B2
    WHERE
    ROWID = :B1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 994 11.12 32.70 784 1505862 1670975 994
    Fetch 0 0.00 0.00 0 0 0 0
    total 995 11.12 32.70 784 1505862 1670975 994

    You can try with Merge
    like
    merge into CRH_CONTRACHEQUE a
    using (select b2,b1 row_id from your source_table  )b--(assuming rowid)
    on (a.rowid=b.row_id)
    when matched then update
    SET FL_MIGRADO = 'S' ,
    and CDHISTORICORUBRICAVINCULO = b.B2

  • Update stored procedure syntax

    Can someone post an example of a stored procedure that is used to update a row in a table with a primary key.... thought it would be easy enough to find an eg on google but no luck so far.
    Cheers

    Hey if you dont have the Primay Key or Any other key
    then for updating the table records, always use the
    Rowid "ABC" in you select statements ie in the Cursor
    and then alsways use that RowId in your update
    statements.
    It will work fast & 100% correct also.!!!!I would have thought the statement:
    Can someone post an example of a stored procedure that is used to update a row in a table with a primary key
    would be good indication that it has a primary key.
    And if you're talking about updating rows from a cursor then surely it would be easier to use a CURSOR ... FOR UPDATE statment and then UPDATE ... WHERE CURRENT ... to update the current row. Why the need for using ROWID's?

  • Updating multiple fields ... need an advice.

    Hello all,
    I have a bit of a trouble with updating multiple fields in one table...
    Lets say we have two tables. Table one is called t_employe for example:
    create table t_employe (
    year number,
    line varchar2(1),
    counter number,
    value number)Lets set some random data into table:
    insert all
    into t_employe (year, line,counter, value)
    values(2011,'3','2946','3344')
    into t_employe (year, line,counter, value)
    values(2011,'3','2947','4433')
    into t_employe (year, line,counter, value)
    values(2011,'3','2948','4455')
    into t_employe (year, line,counter, value)
    values(2011,'3','2949','5544')
    select * from dualOk second table would be:
    create table to_update (
    year number,
    line varchar2(1),
    counter number,
    date_pos_1 date,
    value_pos_1 number,
    date_pos_2 date,
    value_pos_2 number,
    date_pos_3 date,
    value_pos_3 number,
    date_pos_4 date,
    value_pos_4 number,
    date_pos_5 date,
    value_pos_5 number)Data:
    insert all
    into to_update (year, line,counter, date_pos_1,value_pos_1,date_pos_2,value_pos_2,date_pos_3,value_pos_3,date_pos_4,value_pos_4,date_pos_5,value_pos_5)
    values(2011,'3','2946',sysdate,'5434',null,null,null,null,null,null,null,null)
    into to_update (year, line,counter, date_pos_1,value_pos_1,date_pos_2,value_pos_2,date_pos_3,value_pos_3,date_pos_4,value_pos_4,date_pos_5,value_pos_5)
    values(2011,'3','2947',sysdate,'11',sysdate,'123',null,null,null,null,null,null)
    into to_update (year, line,counter, date_pos_1,value_pos_1,date_pos_2,value_pos_2,date_pos_3,value_pos_3,date_pos_4,value_pos_4,date_pos_5,value_pos_5)
    values(2011,'3','2948',sysdate,'33',sysdate,'44',sysdate,'8908',null,null,null,null)
    into to_update (year, line,counter, date_pos_1,value_pos_1,date_pos_2,value_pos_2,date_pos_3,value_pos_3,date_pos_4,value_pos_4,date_pos_5,value_pos_5)
    values(2011,'3','2949',sysdate,'1',sysdate,'2',sysdate,'343',sysdate,'78',null,null)
    select * from dualOk now what i want to do is to update table to_update fields where value_pos is NULL. To explain it better imagine
    collums are from left to right in that order value_pos_1, value_pos_2, value_pos_3 .... Now i would want to check for each row
    if value_pos_1 is null ... if it is then update. Finist with this row and move to the next. If its not move to value_pos_2 in
    same row and again check if its null. If it is ... update, if not, again move forward. Each cullum value_pos_X has a cullom date_pos_x
    which has to be updated same as Value_pos_ cullums (if value_pos_X is null then coresponding date_pos_X will be null as well - thats
    a fact in my table).
    So is this doable by using only one update?
    I manage to write a select statment using case clause which does those things perfectly only for value_pos_X fields. I wonder if i can use it in my
    update statment?
    select
    case when a.value_pos_1 is  null then b.value else
         case when a.value_pos_2 is  null then b.value else
              case when a.value_pos_3 is  null then b.value else
                   case when a.value_pos_4 is  null then b.value else
                        case when a.value_pos_5 is  null then b.value else to_number('99999','9999,99')
    end
    end
    end
    end
    end  as value
    from to_update a,t_employe b
    where a.year = b.year
    and a.line= b.line
    and a.counter = b.counter Any suggestions how to pull this one of?
    Thank you!

    SQL> select  *
      2    from  to_update
      3  /
          YEAR L    COUNTER DATE_POS_ VALUE_POS_1 DATE_POS_ VALUE_POS_2 DATE_POS_ VALUE_POS_3 DATE_POS_ VALUE_POS_4 DATE_POS_ VALUE_POS_5
          2011 3       2946 27-AUG-11        5434
          2011 3       2947 27-AUG-11          11 27-AUG-11         123
          2011 3       2948 27-AUG-11          33 27-AUG-11          44 27-AUG-11        8908
          2011 3       2949 27-AUG-11           1 27-AUG-11           2 27-AUG-11         343 27-AUG-11          78
    SQL> merge
      2    into to_update a
      3    using (
      4           select  a.rowid rid,
      5                   b.value
      6             from  to_update a,
      7                   t_employe b
      8             where a.year = b.year
      9               and a.line= b.line
    10               and a.counter = b.counter
    11          ) b
    12     on (
    13         a.rowid = b.rid
    14        )
    15     when matched then update set value_pos_1 = nvl2(value_pos_1,value_pos_1,b.value),
    16                                  value_pos_2 = nvl2(value_pos_1,nvl2(value_pos_2,value_pos_2,b.value),value_pos_2),
    17                                  value_pos_3 = nvl2(value_pos_1 + value_pos_2,nvl2(value_pos_3,value_pos_3,b.value),value_pos_3),
    18                                  value_pos_4 = nvl2(value_pos_1 + value_pos_2 + value_pos_3,nvl2(value_pos_4,value_pos_4,b.value),value_pos_4),
    19                                  value_pos_5 = nvl2(value_pos_1 + value_pos_2 + value_pos_3 + value_pos_4,nvl2(value_pos_5,value_pos_5,b.value),value_pos_5)
    20  /
    4 rows merged.
    SQL> select  *
      2    from  to_update
      3  /
          YEAR L    COUNTER DATE_POS_ VALUE_POS_1 DATE_POS_ VALUE_POS_2 DATE_POS_ VALUE_POS_3 DATE_POS_ VALUE_POS_4 DATE_POS_ VALUE_POS_5
          2011 3       2946 27-AUG-11        5434                  3344
          2011 3       2947 27-AUG-11          11 27-AUG-11         123                  4433
          2011 3       2948 27-AUG-11          33 27-AUG-11          44 27-AUG-11        8908                  4455
          2011 3       2949 27-AUG-11           1 27-AUG-11           2 27-AUG-11         343 27-AUG-11          78                  5544
    SQL> Or yhis might be more readable:
    merge
      into to_update a
      using (
             select  a.rowid rid,
                     b.value
               from  to_update a,
                     t_employe b
               where a.year = b.year
                 and a.line= b.line
                 and a.counter = b.counter
            ) b
       on (
           a.rowid = b.rid
       when matched then update set value_pos_1 = case when value_pos_1 is null then b.value else value_pos_1 end,
                                    value_pos_2 = case when value_pos_1 is not null and value_pos_2 is null then b.value else value_pos_2 end,
                                    value_pos_3 = case when value_pos_1 + value_pos_2 is not null and value_pos_3 is null then b.value else value_pos_3 end,
                                    value_pos_4 = case when value_pos_1 + value_pos_2 + value_pos_3 is not null and value_pos_4 is null then b.value else value_pos_4 end,
                                    value_pos_5 = case when value_pos_1 + value_pos_2 + value_pos_3 + value_pos_4 is not null and value_pos_5 is null then b.value else value_pos_5 end
    /SY.

  • Manupulate the data from the database and update it back

    hi. i was wondering if it is possible to manupulate the data that we get from the resuletSet and do some manupulation and and again update it back to the same row and column. i tried to do it but could not get it. eg. i want to increase the salary by 10% for all the employee in the salary table. i dont want to use the SQL statement. instead i want to use the java program to increase the salary by 10%.
    what i did was, i selected all the records in the table in the resultset and then i stored the salary one by one through the loos using rs.next() and manupulated the salary by the formula
    salary=salary + salary*10/100.
    then i want to update all the employee with this new salary. i dont know whether it is possible or not.
    i tried to have an UPDATE statement in the while loop with rs.next with the condition but the loop gets terminated once it tries to execute the UPDATE statment and doesnot give any result.
    any help or suggestion will be highly appreciated.

    Here's the general long hand way of doing it. You should also look into your JDBC driver and the use of updateable ResultSets for more effeciency.
    public class SalaryObject {
        private int rowId = 0;
        private double salary = 0.0;
        public void setRowId(int rowId) {
            this.rowId = rowId;
        public int getRowId() {
            return rowId;
        public void setSalary(double salary) {
            this.salary = salary;
        public double getSalary() {
            return salary;
    }Withing your dataccess class:
    Vector salaries = new Vector();
    ResultSet rs = statement.executeQuery("SELECT rowId, salary FROM YOUR_SALARY_TABLE)
    if (rs != null) {
        while(rs.next()) {
            SalaryObject salaryObject = new SalaryObject();
            salaryObject.setRowId(rs.getInt("rowId"));
            double newSalary = rs.getDouble("salary");
            newSalary += newSalary*10/100;
            salaryObject.setSalary(newSalary);
            salaries.add(salaryObject);
        Iterator iter = salaries.iterator();
        while(iter.hasNaxt()) {
            SalaryObject salaryObject = (SalaryObject) iter.next();
            updateSalary(salaryObject.getRowId, salaryObject.getSalary);
        public int updateSalary(int rowId, double newSalary) {
            Connection con = new java.sql.Connection();
            String sql = "UPDATE YOUR_SALARY_TABLE SET salary = ? WHERE rowId = ?"
            PreparedStatement pStmt = con.prepareStatement(sql);
            int success = 0;
            try {
                pStmt.setDouble(1, newSalary);
                pStmt.setInt(2, rowId);
                success = pStmt.executeUpdate();
            } catch (SQLException sqle) {
                // handle exception
            } finally {
                try {
                    if (pStmt != null) pStmt.close();
                    if (con != null) con.close();
                } catch (SQLException sqle) {}
        }

Maybe you are looking for

  • Exp problem in Oracle 10gR2

    Hi, I'm having issues when I try to use exp utility to dump the database as a normal. Here is the error: Message 206 not found; No message file for product=RDBMS, facility=EXP: Release 10.2.0.1.0 - Production on Wed Feb 22 14:54:08 2006 Copyright (c)

  • Regarding restart of services

    Hi Frnds, Can i know what is the sequence to restart the services i.e services like open ldap,Shared services,analytic services,administration services and also the sequence to shut down/restart. Thanks, KRK.

  • Update of SD Documents after Change in Risk category

    Dear Friends, I have a situation in Credit Management. Initially when the Customer master was set up, this customer was set as Risk category "New" to which the credit limit maintained is 1 USD. This customer is having now some Open Orders, Open Sched

  • Can,t open iphoto ???c ....

    I hope this is going to be basic ???? running iphoto 08 ............ uploaded some pictures to i web and then closed iphoto .... now when i go to open iphoto it bounces in the dock and the MAC seems to be wanting to do something but the application w

  • Order closing

    Dear All, I need urgent reply about production order closing. My simple doubt is "when the prod order to be closed? after TECO or befor TECO. What would be the implications in both scenarios? Please give me the replies. This is urgent. Thanks TAJUDDI