Tune Update Statements

An update on a table was taking too long
The column being updated had an index . the time taken to update was around 120 mins (2 hrs) . I dropped the index and then ran the update statement. It took around 10 hrs. So i recreated the index on that column and ran the job. Now the time taken is around 4 hrs
Could you please let me know how to resolve this

> Could you please let me know how to resolve this
By not taking pot shots in the dark.
The first step to any performance problem is Identification.
Identify the problem. Is it slow because of I/O? (e.g. is the process 80% of the time idle, waiting for I/O to complete?). It is because of CPU (e.g. single CPU machine running at 100% CPU busy time). Etc. Etc.
Only once an accurate diagnosis has been made, the problem can be treated.
In a nutshell:
Oracle has two basic measures for this (refer to the Oracle® Database Reference for details on virtual views for these):
- events (what is the session/process up to?)
- wait states (what is the session/process waiting for?)
The other aspect is determing what the process is attempting - just what execution plan results from the UPDATE session. E.g. if the wait states indicates a lot of I/O, the execution plan will point to the likely tables/indexes which is used that's causing this (.e.g full table scan, full index scans, index range scans, intensive/large nested loops, etc)
Also consult the Oracle® Database Performance Tuning Guide.

Similar Messages

  • How to tune the Update statement for 20 million rows

    Hi,
    I want to update 20 million rows of a table. I wrote the PL/SQL code like this:
    DECLARE
    v1
    v2
    cursor C1 is
    select ....
    BEGIN
    Open C1;
    loop
    fetch C1 bulk collect into v1,v2 LIMIT 1000
    exit when C1%NOTFOUND;
    forall i in v1.first..v1.last
    update /*+INDEX(tab indx)*/....
    end loop;
    commit;
    close C1;
    END;
    The above code took 24 mins to update 100k records, so for around 20 million records it will take 4800 mins (80 hrs).
    How can I tune the code further ? Will a simple Update statement, instead of PL/SQL make the update faster ?
    Will adding few more hints help ?
    Thanks for your suggestions.
    Regards,
    Yogini Joshi

    Hello
    You have implemented this update in the slowest possible way. Cursor FOR loops should be absolute last resort. If you post the SQL in your cursor there is a very good chance we can re-code it to be a single update statement with a subquery which will be the fastest possible way to run this. Please remember to use the {noformat}{noformat} tags before and after your code so the formatting is preserved.
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to tune this update statement?

    Hello,
    I have to solve the following task:
    Update every row in table A which has an appropriate row in table B and log what you have done in a log-table.
    It is possible that there are more than one fitting rows in table A for a row in table B.
    My first approach is looping over the table B and doing an update of table A for every entry in table B.
    This works and looks like this:
    Table A:
    PK number (This is the primary key of this table)
    KEY number
    Table B:
    KEY_OLD number
    KEY_NEW number
    Log table:
    PK number
    KEY_OLD number
    KEY_NEW number
    declare
      TYPE PK_TAB_TYPE IS TABLE OF number INDEX BY BINARY_INTEGER;
      v_tab_PK       PK_TAB_TYPE;
      v_empty_tab_PK PK_TAB_TYPE;
    begin
      for v_rec in (select * from table_B) loop
        v_tab_PK := v_empty_tab_PK;  /* clearing the array */
        update table_A
        set    KEY = v_rec.KEY_NEW
        where (KEY = v_rec.KEY_OLD)
        returning PK bulk collect into v_tab_PK;
        if (v_tab_PK.count > 0) then
          for i in v_tab_PK.first..v_tab_PK.last loop
            insert into TMP_TAB_LOG(PK, KEY_OLD, KEY_NEW)
              values (v_tab_PK(i), v_rec.KEY_OLD, v_rec.KEY_NEW);
          end loop;
        end if;
      end loop;
    end;Because the table B can have up to 500.000 entries (and the table A has even more entries) this solution will cause many update-statements.
    So I am looking for a solution which has better performance.
    My second approach was using an correlated update and looks like this:
    declare
      TYPE PK_TAB_TYPE IS TABLE OF number INDEX BY BINARY_INTEGER;
      v_tab_PK            PK_TAB_TYPE;
      v_empty_tab_PK PK_TAB_TYPE;
      v_tab_NewKey    PK_TAB_TYPE;
    begin
      v_tab_PK         := v_empty_tab_PK;  /* clear the arrays */
      v_tab_NewKey := v_empty_tab_PK;
      update table_A a
      set    KEY = (select KEY_NEW from table_B where (KEY_OLD = a.KEY))
      where exists (select 'x' as OK
                         from   table_B
                         where (KEY_OLD = a.KEY)
      returning PK, KEY bulk collect into v_tab_PK, v_tab_NewKey;
      if (v_tab_PK.count > 0) then
        for i in v_tab_PK.first..v_tab_PK.last loop
          insert into TMP_TAB_LOG_DUB(PK, KEY_OLD, KEY_NEW)
            values (v_tab_PK(i), null, v_tab_NewKey(i));
        end loop;
      end if;
    end;Now I have only one update statement.
    The only thing missing in this second approach is the old KEY before the update in the log table.
    But I have no idea how to get the old value.
    Is there a possibility to modify this second approach to get the old value of the KEY before the update to write it in the log-table?
    And now I need your help:
    What is the best way to get a performant solution for my task?
    Every help appreciated.
    Regards Hartmut

    Below is a script you can run in another testing schema to do the update with logging..... I have created the tables (A and B) with primary key constraints defined...
    create table table_a(pk number primary key
    , key number);
    create table table_b(key_old number primary key
    , key_new number);
    create table TMP_TAB_LOG_DUB(pk number primary key
    , key_old number
    , key_new number);
    ---------insert test data
    insert into table_a values(1,2);
    insert into table_a values(2,2);
    insert into table_a values(3,2);
    insert into table_a values(11,1);
    insert into table_a values(12,1);
    insert into table_a values(13,1);
    insert into table_a values(21,4);
    insert into table_a values(22,4);
    insert into table_a values(23,4);
    commit;
    insert into table_b values(1,3);
    insert into table_b values(4,2);
    commit;
    ----- insert to log
    insert into TMP_TAB_LOG_DUB(PK, KEY_OLD, KEY_NEW)
    select a.pk
    , a.key as key_old
    , b.key_new as key_new
    from table_a a
    join table_b b on a.key = b.key_old;
    ----- update table_a
    update(select a.pk
    , a.key as key_old
    , b.key_new as key_new
    from table_a a
    join table_b b on a.key = b.key_old)
    set key_old = key_new;
    commit;

  • Need to tune this Update statement.

    Hi..
    I have an update which I suspect is performing bad.
    UPDATE
         PS_OI_RNV_RCN_RECV R
         SET (VOUCHER_ID, VOUCHER_LINE_NUM) =
         (SELECT
                M.VOUCHER_ID ,
              M.VOUCHER_LINE_NUM
         FROM
              PS_VCHR_RECV_MTCH M
         WHERE
              M.BUSINESS_UNIT = R.BUSINESS_UNIT_GL
         AND      M.BUSINESS_UNIT_PO =  R.BUSINESS_UNIT
         AND      M.RECEIVER_ID = R.RECEIVER_ID
         AND      M.RECV_LN_NBR =  R.RECV_LN_NBR
         AND      (M.RECEIVER_ID, M.RECV_LN_NBR) IN ( SELECT M3.RECEIVER_ID ,M3.RECV_LN_NBR
                                       FROM PS_VCHR_RECV_MTCH M3
                                       WHERE
                                            M3.BUSINESS_UNIT =R.BUSINESS_UNIT_GL
                                       AND M3.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
                                       AND M3.RECEIVER_ID = R.RECEIVER_ID
                                       AND M3.RECV_LN_NBR = R.RECV_LN_NBR
                                       HAVING  COUNT(*) = :"SYS_B_0"
                                       GROUP BY M3.RECEIVER_ID , M3.RECV_LN_NBR
    WHERE
           R.USERID = :"SYS_B_1"
    AND      R.RUN_CNTL_ID = :"SYS_B_2"
    AND      R.VOUCHER_ID =  :"SYS_B_3"
    AND      R.OI_RNV_STATUS = :"SYS_B_4"
    AND      EXISTS ( SELECT VOUCHER_ID ,VOUCHER_LINE_NUM FROM PS_VCHR_RECV_MTCH M2
              WHERE
                   M2.BUSINESS_UNIT = R.BUSINESS_UNIT_GL
                   AND M2.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
                   AND M2.RECEIVER_ID = R.RECEIVER_ID
                   AND M2.RECV_LN_NBR = R.RECV_LN_NBR
                   AND (M2.RECEIVER_ID, M2.RECV_LN_NBR) IN ( SELECT M4.RECEIVER_ID ,M4.RECV_LN_NBR
                                                 FROM PS_VCHR_RECV_MTCH M4
                                                 WHERE M4.BUSINESS_UNIT = R.BUSINESS_UNIT_GL
                                                 AND M4.BUSINESS_UNIT_PO = R.BUSINESS_UNIT
                                                 AND M4.RECEIVER_ID = R.RECEIVER_ID
                                                 AND M4.RECV_LN_NBR = R.RECV_LN_NBR
                                            HAVING  COUNT(*) = :"SYS_B_5"
                                            GROUP BY M4.RECEIVER_ID , M4.RECV_LN_NBR
              )Plan for this Statement is
    | Id  | Operation                | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT         |                    |     1 |    59 |  7413   (1)| 00:01:29 |
    |   1 |  UPDATE                  | PS_OI_RNV_RCN_RECV |       |       |            |          |
    |*  2 |   FILTER                 |                    |       |       |            |          |
    |*  3 |    TABLE ACCESS FULL     | PS_OI_RNV_RCN_RECV |     1 |    59 |   750   (1)| 00:00:09 |
    |*  4 |    INDEX RANGE SCAN      | PS_VCHR_RECV_MTCH  |     1 |    27 |  1110   (1)| 00:00:14 |
    |*  5 |     FILTER               |                    |       |       |            |          |
    |   6 |      SORT GROUP BY NOSORT|                    |     1 |    27 |  1110   (1)| 00:00:14 |
    |*  7 |       INDEX RANGE SCAN   | PS_VCHR_RECV_MTCH  |     1 |    27 |  1110   (1)| 00:00:14 |
    |*  8 |   INDEX RANGE SCAN       | PS_VCHR_RECV_MTCH  |     1 |    40 |  1110   (1)| 00:00:14 |
    |*  9 |    FILTER                |                    |       |       |            |          |
    |  10 |     SORT GROUP BY NOSORT |                    |     1 |    27 |  1110   (1)| 00:00:14 |
    |* 11 |      INDEX RANGE SCAN    | PS_VCHR_RECV_MTCH  |     1 |    27 |  1110   (1)| 00:00:14 |
    Predicate Information (identified by operation id):
       2 - filter( EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "SYS_ALIAS_10" WHERE
                  "M2"."BUSINESS_UNIT"=:B1 AND "M2"."RECEIVER_ID"=:B2 AND "M2"."RECV_LN_NBR"=:B3 AND
                  "M2"."BUSINESS_UNIT_PO"=:B4 AND  EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "M4" WHERE
                  "M4"."BUSINESS_UNIT"=:B5 AND "M4"."RECEIVER_ID"=:B6 AND "M4"."RECV_LN_NBR"=:B7 AND
                  "M4"."BUSINESS_UNIT_PO"=:B8 GROUP BY "M4"."RECEIVER_ID","M4"."RECV_LN_NBR" HAVING
    PLAN_TABLE_OUTPUT
                  "M4"."RECEIVER_ID"=:B9 AND "M4"."RECV_LN_NBR"=:B10 AND COUNT(*)=TO_NUMBER(:SYS_B_5))))
       3 - filter("R"."VOUCHER_ID"=:SYS_B_3 AND "R"."RUN_CNTL_ID"=:SYS_B_2 AND
                  "R"."OI_RNV_STATUS"=:SYS_B_4 AND "R"."USERID"=:SYS_B_1)
       4 - access("M2"."BUSINESS_UNIT"=:B1 AND "M2"."RECEIVER_ID"=:B2 AND
                  "M2"."RECV_LN_NBR"=:B3 AND "M2"."BUSINESS_UNIT_PO"=:B4)
           filter("M2"."RECEIVER_ID"=:B1 AND "M2"."RECV_LN_NBR"=:B2 AND
                  "M2"."BUSINESS_UNIT_PO"=:B3 AND  EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "M4" WHERE
                  "M4"."BUSINESS_UNIT"=:B4 AND "M4"."RECEIVER_ID"=:B5 AND "M4"."RECV_LN_NBR"=:B6 AND
                  "M4"."BUSINESS_UNIT_PO"=:B7 GROUP BY "M4"."RECEIVER_ID","M4"."RECV_LN_NBR" HAVING
                  "M4"."RECEIVER_ID"=:B8 AND "M4"."RECV_LN_NBR"=:B9 AND COUNT(*)=TO_NUMBER(:SYS_B_5)))
       5 - filter("M4"."RECEIVER_ID"=:B1 AND "M4"."RECV_LN_NBR"=:B2 AND
                  COUNT(*)=TO_NUMBER(:SYS_B_5))
       7 - access("M4"."BUSINESS_UNIT"=:B1 AND "M4"."RECEIVER_ID"=:B2 AND
                  "M4"."RECV_LN_NBR"=:B3 AND "M4"."BUSINESS_UNIT_PO"=:B4)
           filter("M4"."RECEIVER_ID"=:B1 AND "M4"."RECV_LN_NBR"=:B2 AND
                  "M4"."BUSINESS_UNIT_PO"=:B3)
       8 - access("M"."BUSINESS_UNIT"=:B1 AND "M"."RECEIVER_ID"=:B2 AND
                  "M"."RECV_LN_NBR"=:B3 AND "M"."BUSINESS_UNIT_PO"=:B4)
           filter("M"."RECEIVER_ID"=:B1 AND "M"."RECV_LN_NBR"=:B2 AND
                  "M"."BUSINESS_UNIT_PO"=:B3 AND  EXISTS (SELECT 0 FROM "PS_VCHR_RECV_MTCH" "M3" WHERE
                  "M3"."BUSINESS_UNIT"=:B4 AND "M3"."RECEIVER_ID"=:B5 AND "M3"."RECV_LN_NBR"=:B6 AND
                  "M3"."BUSINESS_UNIT_PO"=:B7 GROUP BY "M3"."RECEIVER_ID","M3"."RECV_LN_NBR" HAVING
                  "M3"."RECEIVER_ID"=:B8 AND "M3"."RECV_LN_NBR"=:B9 AND COUNT(*)=TO_NUMBER(:SYS_B_0)))
       9 - filter("M3"."RECEIVER_ID"=:B1 AND "M3"."RECV_LN_NBR"=:B2 AND
                  COUNT(*)=TO_NUMBER(:SYS_B_0))
      11 - access("M3"."BUSINESS_UNIT"=:B1 AND "M3"."RECEIVER_ID"=:B2 AND
                  "M3"."RECV_LN_NBR"=:B3 AND "M3"."BUSINESS_UNIT_PO"=:B4)
    PLAN_TABLE_OUTPUT
           filter("M3"."RECEIVER_ID"=:B1 AND "M3"."RECV_LN_NBR"=:B2 AND
                  "M3"."BUSINESS_UNIT_PO"=:B3)
    DBMS_METADATA.GET_DDL('INDEX','PS_VCHR_RECV_MTCH')
      CREATE UNIQUE INDEX "SYSADM"."PS_VCHR_RECV_MTCH" ON "SYSADM"."PS_VCHR_RECV_MTC
    H" ("BUSINESS_UNIT", "VOUCHER_ID", "VOUCHER_LINE_NUM", "BUSINESS_UNIT_RECV", "RE
    CEIVER_ID", "RECV_LN_NBR", "RECV_SHIP_SEQ_NBR", "BUSINESS_UNIT_PO", "PO_ID", "LI
    NE_NBR", "SCHED_NBR")
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
      STORAGE(INITIAL 40960 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "PSINDEX"
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1   2007.68    2012.83          2  182564670       4260        4070
    Fetch        0      0.00       0.00          0          0          0           0
    total        2   2007.68    2012.83          2  182564670       4260        4070Thanks...
    Edited by: Oceaner on May 24, 2012 7:15 AM

    Hi Gokul,
    in case of no statistics most likely the optimizer would do a dynamic sampling, so ironically, no statistics is often better than statistics.
    It could be that some of the tables is used as a temp table (i.e. is filled with data to carry out some operations, and then purged), in which case the stats job could've caught it when it was empty. But even if the cardinalities would have been fine, I don't really think the optimizer has a lot of options with the query as is stands, because the aggregate subqueries restrict the ability of the optimizer to apply query transforms.
    Still, worth a shot to check if stats are accurate -- that's an easy thing to do and couldn't possibly do any harm.
    Best regards,
    Nikolay

  • Large amount of update statements

    Dear experts,
    I have to perform a large amount of update statements on a db2 table.
    I first tried to do it via a UNIX shell script with statements like below:
    db2 "update <schema>.<tablename> set value = 'xxxx' where ELEMENT = 'YYYY' and WI_ID = 'nnnnnnn'"
    Only this takes forever.
    Could you please tell me what the most efficient way is to do this.
    I thank you for your time
    Regards
    Dirk Visser

    Is this SAP, as not sure SAP are too keen on direct SQL ?
    I will assume this is not SAP, as the below would not be SAP approved.
    Some comments:
    - A stored procedure would be faster then an UNIX script for a couple of reasons
    - Sounds like you might need to tune your logging I/O and/or your I/O in general
    - You could group the Updates, turn auto-commit off, and explicitly commit every N records. You need to ensure you don't have a UOW too large, as your TXN logs will run out of space.
    - You can turn logging off during the updates - but I'd rather not go there if this is a SAP System. Plus the operation would be non-recoverable.
    Recommend the following article:
    http://www.ibm.com/developerworks/db2/library/techarticle/dm-0403wilkins/

  • Bulk SQL Update Statements

    I need to perform bulk updates on my tables using SQL. The tables are really very big and most of updates occur on couple of million records. As such the process is time consuming and very slow. Is there anything I could do to fine tune these update statements? Please advise. Some of the same SQL statements I use are as follows
    update test set gid=1 where gid is null and pid between 0 and 1;
    update test set gid=2 where gid is null and pid between 1 and 5;
    update test set gid=3 where gid is null and pid between 5 and 10;
    update test set gid=4 where gid is null and pid between 10 and 15;
    update test set gid=5 where gid is null and pid between 15 and 70;
    update test set gid=6 where gid is null and pid between 70 and 100;
    update test set gid=7 where gid is null and pid between 100 and 150;
    update test set gid=8 where gid is null and pid between 150 and 200;
    update test set gid=9 where gid is null and pid between 200 and 300;
    Message was edited by:
    user567669

    Indeed, check out the predicate:
    SQL> explain plan for
      2  select *
      3  from emp
      4  where sal between 1000 and 2000;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     5 |   185 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| EMP  |     5 |   185 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter("SAL"<=2000 AND "SAL">=1000)

  • Update statements tuning

    Hello,
    I am working on Oracle 10.2.0.4 and O/S is solaris .
    We are having one job which exceutes lots of update statements one by one on database. The whole job is taking more then 2 hours.
    I check that we can not do mach changes in sql tuning side to tune this query , is there any way to reduce time in oracle side like some parameter setting ..
    resizing buffer , redo log files or ..?
    any idea...

    thanks helios,
    I will check this link ..
    this states to make changes in sql statements
    but as this is a product and changing sql statements will take lots of approvals and money and efforts to customize product but yes we can try with that.
    I am looking for some database side options .so that we can tune it maximum and minimize time taken in job.
    Is there any options we have .. as redo log size , checkpoint interval etc.. to do it .
    what are the optimized values for these in high frequency of update statements environment.

  • Decode function in Update statement

    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!

    882300 wrote:
    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!If you really really really want to update the entire table, the syntax would be...
    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
    ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
    Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
    http://wikis.sun.com/display/Forums/Forums+FAQ

  • Unable to execute an update statement using CallableStatement

    Hi there,
    I'm trying to run an update statement from JUnit using java.sql.CallableStatement and oracle.jbo.server.DBTransaction.
            String updateSql =
                "update footable set barcol=TO_DATE('12-SEP-09','dd-MM-yy') where bazcol = 505";
            try {
                statement =
                        applnModule.getDBTransaction().createCallableStatement(updateSql,
                                                                               2);
                int executeUpdate = statement.executeUpdate();
                AppsLogger.write(this,
                                 "# records UPDATED ------------------>" + executeUpdate,
                                 AppsLogger.SEVERE);
            } catch (SQLException s) {
                s.printStackTrace();
                Assert.fail("Encountered SQL Exception: " + s);
            } finally {
                try {
                    if (statement != null)
                        statement.close();
                } catch (SQLException s) {
            }Below is the exception I get when I run the above code. There is no problem with the SQL - it works fine from SQLDeveloper.
    java.lang.AssertionError: Encountered SQL Exception: java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
         org.junit.Assert.fail(Assert.java:91)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
         org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:105)
         org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
         org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
         org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
         org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.invokeTestMethod(AtfJUnit4JTestCaseClassRunner.java:362)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.runMethods(AtfJUnit4JTestCaseClassRunner.java:272)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner$1.run(AtfJUnit4JTestCaseClassRunner.java:265)
         org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
         org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
         oracle.apps.common.applicationsTestFramework.junit.internal.AtfJUnit4JTestCaseClassRunner.run(AtfJUnit4JTestCaseClassRunner.java:262)Edited by: 911023 on Oct 2, 2012 11:28 AM
    Edited by: 911023 on Oct 2, 2012 11:30 AM

    Using case statement.
    UPDATE gor_gold_post
       SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
                                   OR
                                   (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
                                AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
                           THEN 1
                           ELSE 99
                         END,
           b49n      = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
                             OR
                             (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
                                AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
                           THEN 1
                           ELSE 99
                         END
    WHERE tariff_code IN (169, 135, 136);Note: Code not tested.

  • Is their any limit on the number of column updates in a update statement!

    Hello All,
    Is their any limit on the number of columns to set in a single update statement.+
    am using oracle 11g .
    example :-
    UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5 ,      perslt18 = v_perslt18 , persot64  = v_persot64  , fam_size = v_fam_size , numchild = total_children , C_AGE1 = v_c_age1,  C_AGE2 = v_c_age2,  C_AGE3 = v_c_age3,  C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
    and also is it good practice to issue single update or multiple updates ?
    example for the above update i can have multiple statements like .. does the performance matters if so which is good
    UPDATE FMLY SET as_comp1 = v_as_comp1 , as_comp2 = v_as_comp2, as_comp3 = v_as_comp3, as_comp4 = v_as_comp4 , as_comp5 = v_as_comp5
    WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET perslt18 = v_perslt18 , persot64 = v_persot64 , fam_size = v_fam_size
    WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET numchild = total_children WHERE FAMID = fmly_famid(i) ;
    UPDATE FMLY SET C_AGE1 = v_c_age1, C_AGE2 = v_c_age2, C_AGE3 = v_c_age3, C_AGE4 = v_c_age4 WHERE FAMID = fmly_famid(i) ;
    thanks/kumar
    Edited by: kumar73 on Sep 25, 2010 8:38 AM

    If you can do it in a single SQL statement then you should do that.
    Here's a mantra that I found to work out pretty good:
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:73891904732164

  • Error while schedulingg update stat in db13

    Dear Experts,
    Please look into my issue we are facing an error while scheduling update statistics in db13 and I tried to open detailed log
    It is given
    SXPG_COMMAND_EXECUTE failed for BRTOOLS - Reason: program_start_error: For More Information, See SYS
    Please help me how to solve this my error
    Regards

    Hi,
    Check the owner for BRBACKUP, BRARCHIVE, and BRCONNECT in kernel,
    these files should be with SIDADM, if not change the owner to SIDADM and rerun the update stats.
    and also Refer the note 446172
    Regards,
    Ram

  • How do I pass multiple values from a text box to an update statement

    I hope this does not sound to lame. I am trying to update multiple values Like this:
    Code|| Computer Desc || Computer Price || Computer Name
    SEL1 || Apple macbook || 1564 || Apple Macbook Basic
    SEL2 || Dell 630 || 1470 || Dell Latitude
    I want to change all six values at once in one update statement based on the Code, I can't find a good tutorial/example to help me.
    Can anyone point me in the right direction?
    Thanks so much,
    Laura

    You can do conditional updates with decode or case statements e.g.
    SQL> create table t as
      2  select 'SEL1' as code, 'Apple macbook' as comp_desc, 1564 as comp_price, 'Apple Maxbook Basic' as comp_name from dual union
      3  select 'SEL2', 'Dell 630', 1470, 'Dell Latitude' from dual
      4  /
    Table created.
    SQL>
    SQL> update t
      2  set comp_desc = CASE code WHEN 'SEL1' THEN 'Test1' Else 'Test2' END,
      3      comp_price = CASE code WHEN 'SEL1' THEN 1234 Else 2345 END,
      4      comp_name = CASE code WHEN 'SEL1' THEN 'Test1 Name' Else 'Test2 Name' END
      5  /
    2 rows updated.
    SQL>
    SQL> select * from t
      2  /
    CODE COMP_DESC     COMP_PRICE COMP_NAME
    SEL1 Test1               1234 Test1 Name
    SEL2 Test2               2345 Test2 Name
    SQL>

  • TS5376 For about 4 months now I have been getting an Apple I-Tunes update message but when I try to install it, the program stops and refuses to install it saying I need to go to tools and manually install. the support page says:1. Remove iTunes and relat

    Dear Windows support personel,
         As part of my message reads above; I keep getting an i-tunes update message and when I click on the OK to download it, I get an error message saying there was a problem and I need to go to Tools>manual download.  Well, I don't know how to do that even though I gave it my best try. I went to the support sight and it had the following message;
    1. Remove iTunes and related components from the Control Panel
    Use the Control Panel to uninstall iTunes and related software components in the following order. Then, restart your computer:
    iTunes
    Apple Software Update
    Apple Mobile Device Support
    Bonjour
    Apple Application Support (iTunes 9 or later)
    Important: Uninstalling these components in a different order, or  only uninstalling some of these components, may have unintended affects.
    If you encounter an error while uninstalling, try repairing the affected component:
    I don't know if I should do that since I'm not PC savey. Could you help me by doing the work on my pc for me? I'd be most apprieciative if you'd help me in this manner.
    Sincerely,
    Christine Bocker
    <Email Edited by Host>

    Let's first try updating using an installer file downloaded from the Apple Website:
    http://www.apple.com/itunes/download/

  • Need help to write a query for Update statement with  join

    Hi there,
    The following update statement gives me error as the given table in set statement is invalid. But its the right table .
    Is the statement correct? Please help .
    update (
           select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)            
             from vpproadside.VEHICLE_CRED_OVERRIDE
             join vpproadside.vpp_vehicle
               on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
            where VPP_CARRIER_SEQ_NUMBER = 90
              and EXPIRY_DATE = '17-MAR-10'
       set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
    Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
    Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
    Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:28 AM

    Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797

  • Running an update statement on two dependent attributes

    Dear All,
    I have a repair_job table that contains values for work_cost, parts_cost and total_cost which is the sum of the work and parts cost values. I want to run an update statement that doubles the work cost and, naturally, updates the value of total cost as well. I tried to run it as:
    update repair_job
    set work_cost = 2 * work_cost, total_cost = work_cost + parts_cost
    where licence in (
    select licence from car
    where year = to_char(sysdate,'YYYY')
    thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
    I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
    I look forward to hearing from you soon.
    Regards,
    George

    Welcome to the forum!
    >
    thinking that because the update of work_cost is first on the list, the updated value of total cost would be correct. It seems however that the update of total cost happens first and then the work cost is been updated; not sure what the reason is for that and it happens no matter what the order is in the update statement.
    I know that I can do it in two separate statements, or use a trigger or PL/SQL to do it but I am curious as to why it has this behaviour. Also, is there a way to do it in a single SQL statement - i.e. forcing the update of the work_cost attribute first and then that of total_cost?
    >
    The update to all columns of the row happen at the same time - there is no order involved.
    You don't need two statements but you do need to do the updates based on the current value of the columns.
    set work_cost = 2 * work_cost, total_cost = 2 * work_cost + parts_cost----------
    In addition to sb92075's comments in 11 g you could also just define a virtual column for total_cost and then just query it like you do now.
    total_cost   NUMBER GENERATED ALWAYS AS (work_cost + parts_cost) VIRTUAL,See this Oracle-base article for an example
    http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php
    Edited to supplement sb92075's reply by mentioning virtual columns

Maybe you are looking for

  • Unable to download pdf files from emails or websites

    I used to be able to download pdf files from emails and websites on my Windows vista 2007 computer, but am now unable to save or download them.  Is there something I need to adjust in my security system which hasn't changed?

  • DV capture quality in CS3 vs CS6

    I am capturing Hi8 & Digital8 footage via firewire. I recently purchased Premiere CS6 but I have an older computer that is running CS3. I would like to dedicate that PC to capturing several hundred hours of footage rather than tying up my current PC.

  • Internal Muxing Error

    Hey guys, came across something very interesting today. for the first time i received this error when building my project. initially i thought it was a bad VTS, since i was just re-using the same one as a template. i deleted it, created a new VTS and

  • Disk size based on content database size

    Hi, Assuming that by the formulae Database size = ((D × V) × S) + (10 KB × (L + (V × D))) my DB size is 105 GB, what should we recommend be the Hard disk size for creating this data base? Thank you, Kotamarthi

  • Function Module or BAPI for Deliveries

    I need to interface the Deliveries from a flat file into APO.  Can someone tell me the function module or BAPI that is used to create the Delivery (ATP Category BR) in APO DRP? Thanks. Sandy