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

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.

  • 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;

  • 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 one character in a string

    Hello Experts,
    I would like to update a character in a string in a column using update statment.
    For eg in table a1 column has "ABCDEF", I would like change "C" with "c" . After change the a1 value should be "ABcDEF".
    Any help will be highly appreciated.
    Regards,
    Rashida

    Use Translate Function
    Example
    SQL> select translate('ABCDEF','C','c') from dual ;
    TRANSL
    ABcDEF
    Or Replace Function
    Exmaple
    SQL> select replace('ABCDEF','C','c') from dual ;
    REPLAC
    ABcDEF
    for table with column a1
    update a1 set col1 =  replace(col1,'C','c') ;
    OR
    update a1 set col1 =  translate(col1,'C','c') ;

  • Update statement in sql

    I want to update table xx whose column is yy
    where column value is successful it should be updated with successfully recharged
    where column value is failure it should be updated with permanently failed
    Can both of these updates are possible in a single update statment
    I am able to use
    update xx set yy='Successfully Recharged' where yy='Successful' --for a single statement
    Thanks,

    You may also use DECODE like:
    UPDATE xx
       SET yy =
              DECODE (yy,
                      'successful', 'successfully recharged',
                      'failure', 'permanently failed')
    WHERE yy IN ('successful', 'failure')The where clause is mentioned if there were more values in yy column and we don't want to update those records.
    Saad,

  • Unecessary use of SELECT...FOR UPDATE causing Deadlock

    DB version:10gR2
    We are getting a deadlock issue frequently. When i looked at the trace file i found that the <em>Rolled back SQL</em> and the <em>Successfull SQL</em> are both <strong>SELECT FOR UPDATE</strong> statements. They both are declared before UPDATE statments.
    Both of these PL/SQL codes are developed by a C++ guy. When is it appropriate to use SELECT ..FOR UPDATE. I've seen SELECT ...FOR UPDATE very rarely in the codes developed by PL/SQL gurus in our firm. Why didn't they use SELECT..FOR UPDATE to lock rows before UPDATE/DELETE/INSERT in their codes?

    For update is a rowlevel locking. like
    Session 1
    SQL> conn scott/tiger
    Connected.
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    14 rows selected.
    SQL> select * from emp where empno = 7369 for update;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
    SQL>
    Session 2
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> update emp set sal = 1000 where empno = 7900
      2  /
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL> update emp set sal = 1000 where empno = 7369
      2
    SQL> /In session 1 we have lock row where empno = 7369 & in session 2 we are updating salary where empno = 7900 it is updating successfully, but we are updating a empno = 7369 then session 2nd hangs for waiting for the next session.
    Also read the Link (http://www.oracle.com/technology/oramag/oracle/05-nov/o65asktom.html)

  • [8i] Need help updating/fixing a workday table

    I'm working in an old database:
    Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
    PL/SQL Release 8.1.7.2.0 - Production
    CORE 8.1.7.0.0 Production
    TNS for HPUX: Version 8.1.7.2.0 - Production
    NLSRTL Version 3.4.1.0.0 - Production
    I'm trying to fix a workday calendar, and I'm not exactly sure how to do it. I'm used to querying data, not making changes to the data...
    Here's some sample data:
    CREATE TABLE     test_cal
    (     clndr_dt     DATE     NOT NULL
    ,     work_day     NUMBER(3)
    ,     clndr_days     NUMBER(6)
    ,     work_days     NUMBER(5)
    INSERT INTO     test_cal
    VALUES     (TO_DATE('12/30/2010','mm/dd/yyyy'), 254, 11322, 7885);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('12/31/2010','mm/dd/yyyy'), 255, 11323, 7886);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/01/2011','mm/dd/yyyy'), 0, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/02/2011','mm/dd/yyyy'), 0, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/03/2011','mm/dd/yyyy'), 1, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/04/2011','mm/dd/yyyy'), 2, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/05/2011','mm/dd/yyyy'), 3, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/06/2011','mm/dd/yyyy'), 4, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/07/2011','mm/dd/yyyy'), 5, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/08/2011','mm/dd/yyyy'), 0, NULL, NULL);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/09/2011','mm/dd/yyyy'), 0, 11332, 7895);
    INSERT INTO     test_cal
    VALUES     (TO_DATE('01/10/2011','mm/dd/yyyy'), 6, 11333, 7896);Note: 12/31/2010 is the last time I am 100% sure the data in the table is good. After that, clndr_days and work_days are either missing or, at least in the case of work_days, are not correct.
    This is a two-part question, since I need to fix both clndr_days and work_days. (You can probably fix them both with one statement, but I broke it into two to start, to simplify it for myself).
    I only show 12 days in my sample data, but really, the table stretches back a number of years, and forward another 5 or so years.
    PART 1: fixing clndr_days
    I put together this query:
    SELECT     clndr_dt
    ,     work_day
    ,     work_days
    ,     clndr_days
    ,     min_clndr_day + r_num     AS clndr_days_test
    FROM     (
         SELECT     t.*
         ,     MIN(clndr_days)     OVER(ORDER BY clndr_dt)     AS min_clndr_day
         ,     ROW_NUMBER() OVER(ORDER BY clndr_dt)-1     AS r_num
         FROM     test_cal t
         WHERE     clndr_dt     >= TO_DATE('12/31/2010','mm/dd/yyyy')
    ;Which gives the right clndr_days (as clndr_days_test), but I'm not sure how to get that into the table.
    This doesn't work:
    UPDATE     test_cal
    SET     clndr_days     =     (
                        SELECT     min_clndr_day + r_num
                        FROM     (
                             SELECT     t.*
                             ,     MIN(clndr_days)     OVER(ORDER BY clndr_dt)     AS min_clndr_day
                             ,     ROW_NUMBER() OVER(ORDER BY clndr_dt)-1     AS r_num
                             FROM     test_cal t
                             WHERE     clndr_dt     >= TO_DATE('12/31/2010','mm/dd/yyyy')
                             ) c
                        WHERE     c.clndr_dt     = ???  -- how do I make this equal whatever the clndr_dt is for the record I'm updating?
    WHERE     clndr_dt     >      TO_DATE('12/31/2010','mm/dd/yyyy')and I'm not sure how to make it work...
    PART 2: Fixing work_days
    Then, I can't seem to put together a query for work_days.
    This is what I have so far, but it doesn't work quite right, and then it also needs to be an UPDATE statement as well:
    SELECT     clndr_dt
    ,     work_day
    ,     work_days
    ,     clndr_days
    ,     min_work_day + r_num     AS work_days_test --this isn't right, when work_day is 0 work_days_test should be the previous work_day not the minimum work_day
    FROM     (
         SELECT     t.*
         ,     MIN(work_days)     OVER ( ORDER BY clndr_dt)     AS min_work_day
         ,     CASE
                   WHEN     work_day     <> 0
                   THEN     ROW_NUMBER()     OVER ( PARTITION BY     CASE
                                                      WHEN     work_day <> 0
                                                      THEN     1
                                                      ELSE     2
                                                 END
                                         ORDER BY     clndr_dt
                   ELSE     0
              END               AS r_num
         FROM     test_cal t
         WHERE     clndr_dt     >= TO_DATE('12/31/2010','mm/dd/yyyy')
    ;(When I tried using LAG, that didn't work either, because you can have more than 1 non-work day in a row, and so it only works for the first non-work day to have the correct work_days, and then it's back to being wrong again)
    This is what I want my table to look like in the end:
    CLNDR_DT                   WORK_DAY       WORK_DAYS CLNDR_DAYS_TEST
    12-31-2010 00:00:00         255.000       7,886.000    11,323.000
    01-01-2011 00:00:00            .000       7,886.000    11,324.000
    01-02-2011 00:00:00            .000       7,886.000    11,325.000
    01-03-2011 00:00:00           1.000       7,887.000    11,326.000
    01-04-2011 00:00:00           2.000       7,888.000    11,327.000
    01-05-2011 00:00:00           3.000       7,889.000    11,328.000
    01-06-2011 00:00:00           4.000       7,890.000    11,329.000
    01-07-2011 00:00:00           5.000       7,891.000    11,330.000
    01-08-2011 00:00:00            .000       7,891.000    11,331.000
    01-09-2011 00:00:00            .000       7,891.000    11,332.000
    01-10-2011 00:00:00           6.000       7,892.000    11,333.000(sorry about all the extra decimal places)
    Edited by: user11033437 on Jan 11, 2012 1:40 PM

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statements, the very clear desired output, and your attempts; that's all very helpful. It would also be helpful to explain how you get the results you want from the sample data. There's always a chance someone might coincidentally get the right results for the wrong reasons with the small set of sample data, but would cause you to get wrong results with your full data.
    It looks like clndr_days is the total number of days since some conventional starting point (maybe when the company started), and that work_days is the total number of work days from some starting point. It looks like work_day is 0 when the day is not a working day, and otherwise, it's the total number of working days so far in the calendar year. Is that right?
    You said the data after December 31, 2010 isn't reliable. Did you mean that two columns (clndr_days and work_days) are unreliable, but the rest of the data is reliable? That is, are you sure there is exactly one row per day even after 2010, and that the work_day column is accurate? If so, you can do this:
    UPDATE       test_cal     m
    SET       (clndr_days, work_days) =
         SELECT     MIN (clndr_days) + COUNT (*) - 1          -- clndr_days
         ,     MIN (work_days)  + COUNT ( CASE
                                               WHEN  work_day > 0
                                    AND   clndr_dt > TO_DATE ('12/31/2010', 'MM/DD/YYYY')
                                    THEN  1
                                END
                                 )               -- work_days
         FROM     test_cal
         WHERE     clndr_dt     BETWEEN     TO_DATE ('12/31/2010', 'MM/DD/YYYY')
                        AND     m.clndr_dt
    WHERE     clndr_dt     > TO_DATE ('12/31/2010', 'MM/DD/YYYY')
    ;You were right: it is possible to set both columns at the same time.
    It's a shame that you're using Oracle 8.1. The MERGE command, which was new in Oracle 9.1, is a lot clearer and more efficient. If you could use MERGE, you could basically use the code you posted as the core of a MERGE statement.
    The UPDATE statement above assumes that, for the inaccurate days, clndr_days and work_days will never be lower than the last accurate value. If that's not the case, the solution is a little more complicated. You could avoid that problem, and make the statment faster as well, by simply hard-coding the last accurate values of clndr_days and work_days in the UPDATE statment, where I used MIN. (This sounds like one situation where efficientcy isn't a big deal, however. You'll probably never do this exact UPDATE statement again, so whether it runs in 1 second or 10 minutes might not matter much.)
    Sorry, I don't have an Oracle 8 database to test this. It works in Oracle 9.2, and I don't believe it uses any features that aren't available in 8.1.

Maybe you are looking for

  • Livecache lock handler not available in APO

    Hello Experts, We are getting the error "Livecache lock handler not available" error when we are running planning jobs in SAP APO. We are using parallel processing profiles for DP background processing jobs (Macro calculations) and I am getting this

  • Error handling when removing expired stuff

    8.1.7.1.0 on Sun... Trying to delete expired backups when, in fact, there aren't any expired backups does not return an error. And it shouldn't. This is correct. Trying to delete expired backup sets older than a specific date when there aren't any re

  • Standard function modules for selection from vbak/vbup/ekko/ekpo

    hi experts , do you know if there is an existing standard function modules for selection from vbak/vbup/ekko/ekpo. please help

  • FBCJ -cash receipt validations

    Dear all, IT'S VERY URGENT In FBCJ transaction under the tab 'Cash Receipts', I want to do the following validations. The amount value is entered under the column 'amount',then sale order number is entered under the column 'sales order'. Now my requi

  • Can someone explain the concept of "Default Timeline"?

    I try to understand coding in edge in more detail. What i do not understand is the concept of named timeline(s): * so if i want to listen to timeline - events of a symbol, i allways have to give the name of the timeline. example: Symbol.bindTriggerAc