Suggestions on update statement

Can any one suggest any 11.1.0.7 hints / parameters on improving Update statement performance.
Ideally it would be a alter session setting.
It is a batch job and I need to improve the performance of it, the table is about 20 Million rows and we are updating about 800,000 rows.
Thanks

Ideally it would be a alter session setting.ALTER SESSION SET MAKEUPDATE_FASTER=TRUE;
Does UPDATE include SELECT clause?
post SQL & EXPLAIN PLAN

Similar Messages

  • Problem in Update Statement

    I got some problem in update statement.Can anybody discuss with me regarding my problem? Below is the occured problem.
    //all the declaration like Connection, ResultSet are declared, setting the ODBC path and so on steps have been set up before this method. When compile it, no error, when I start to run my program, the program�s interface is shown, but the following error was appearred and data cannot be updated, can anybody tell me where is my mistake?
    //ERROR:SQL Error in update statement:java.sql.SQLException [Microsoft][ODBC][ODBC Microsoft Access Driver] Syntax Error in UPDATE statement.
    //emp_overview is the table name
    // last_name, first_name, office_phone�.is the attributes of the table
    //this method had declare in the interface class already
    public String updateData (String idd, String ln, String fn, String op,
                   String oe, String hp, String ps, String ss)
                   throws java.rmi.RemoteException
         {//begin of this method
              String result ="";
              try
              Statement statement = connection.createStatement();
              String sql = "UPDATE emp_overview SET" +
              "last_name=' "+ln+
              " ', first_name=' "+fn+
              " ', office_phone=' "+op+
              " ', office_ext=' "+oe+
              " ', home_phone=' "+hp+
              " ', primary_skill=' "+ps+
              " ', secondary_skill=' "+ss+
              " ' WHERE id="+idd;
              statement.executeUpdate(sql);
              statement.close();
              catch (java.sql.SQLException e)
         System.out.println("SQL Error in update statement: "+e);
              //throw a RemoteException with the exception
              //embedded for the client to receive
         throw new java.rmi.RemoteException("Error in Updating exist row into DB", e);
              return result;
         }//end of this method

    Hi Kevin,
    According to the code you have posted, it looks like you are missing a space between "SET" and "last_name". I suggest you add the following line of code:
    System.out.println(sql);
    before the invocation of "executeUpdate()".
    I also suggest you add the following line of code:
    e.printStackTrace();in your "catch" block.
    Hope this helps.
    Good Luck,
    Avi.

  • Update statement is not working(urgent)

    Hi,
    when i use below code it gives me dump when reocrds arem ore.
    loop at itab.
      update de1000 SET vrprs = itab-rfwrt
      where kaufn = itab-vbelv
      and mtpos IN  soption and perio =  perio and VRPRS <> 0.
    endloop.
    the structure of itab and de11000 is not same.
    please suggest me alternative.
    thanks
    jack

    I believe you can not use update statement with in loop & endloop. it will dump.
    Here is further info. Create another internal table with
    the same structure of de1000 and update the table with required values. finally use the following state
    update de1000 from table t_de1000(internal table)(check syntex)
    Reward if useful
    Message was edited by:
            Nallasamy Ponnusamy

  • Performance degradation in Update statement

    Hi
    I have a table t1 with 3 of the columns as :- c1 ,c2,c3.
    there is a non unique index on c2 ,c3.
    I am using an update statement as : update t1 set c1="value" where c2="some_value" and c3="some_value2" ;
    this works fine in case the number of rows for the same c2 and c3 are less (~100) but takes a large time when ~30,000.
    And it has to be run many times in my application (time out is occuring now)
    Can anybody suggest a solution ?
    Thanks
    Message was edited by:
    user580975

    First off, setting a table to NOLOGGING does not affect the rate of redo generation unless you are also doing direct-path inserts (which is obviously not the case here and which come with their own set of issues). Note that the amount of redo being generated in these two examples is quite similar.
    SCOTT @ jcave102 Local> create table all_obj_cpy as select * from all_objects;
    Table created.
    Elapsed: 00:00:10.78
    SCOTT @ jcave102 Local> set autotrace traceonly;
    SCOTT @ jcave102 Local> alter table all_obj_cpy logging;
    Table altered.
    Elapsed: 00:00:00.01
    SCOTT @ jcave102 Local> update all_obj_cpy
      2  set last_ddl_time = sysdate - 1;
    42511 rows updated.
    Elapsed: 00:00:01.45
    Execution Plan
    Plan hash value: 1645016300
    | Id  | Operation          | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |             | 43776 |   384K|   137   (3)| 00:00:02 |
    |   1 |  UPDATE            | ALL_OBJ_CPY |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| ALL_OBJ_CPY | 43776 |   384K|   137   (3)| 00:00:02 |
    Note
       - dynamic sampling used for this statement
    Statistics
            556  recursive calls
          46075  db block gets
           1558  consistent gets
              0  physical reads
       13575764  redo size
            924  bytes sent via SQL*Net to client
            965  bytes received via SQL*Net from client
              6  SQL*Net roundtrips to/from client
              6  sorts (memory)
              0  sorts (disk)
          42511  rows processed
    SCOTT @ jcave102 Local> alter table all_obj_cpy nologging;
    Table altered.
    Elapsed: 00:00:00.01
    SCOTT @ jcave102 Local> update all_obj_cpy
      2  set last_ddl_time = sysdate - 2;
    42511 rows updated.
    Elapsed: 00:00:01.32
    Execution Plan
    Plan hash value: 1645016300
    | Id  | Operation          | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |             | 43776 |   384K|   137   (3)| 00:00:02 |
    |   1 |  UPDATE            | ALL_OBJ_CPY |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| ALL_OBJ_CPY | 43776 |   384K|   137   (3)| 00:00:02 |
    Note
       - dynamic sampling used for this statement
    Statistics
            561  recursive calls
          44949  db block gets
           1496  consistent gets
              0  physical reads
       12799600  redo size
            924  bytes sent via SQL*Net to client
            965  bytes received via SQL*Net from client
              6  SQL*Net roundtrips to/from client
              6  sorts (memory)
              0  sorts (disk)
          42511  rows processedSecond, if you did manage to do an unlogged operation, make absolutely certain you understand the recovery implications. You must do a complete backup of the database after an unlogged operation or the table will not be recovered in the event of a database failure. If you have a standby database for disaster recovery, unlogged operations would cause the standby to be useless (hence the option to force logging at the tablespace and/or database level).
    While it's certainly possible that this is an Oracle server configuration problem, it would be relatively tough to configure a system so that a 30,000 row update would force excessive log switches. If it were a configuration problem, you'd expect that any update of 30,000 rows would be slow and that multiple sessions running smaller updates would also be slow, but I don't believe that describes the symptoms the original poster is concerned about.
    Justin

  • Function call in update statement

    Hi,
    I have an update statement as follows
    update
    tableA
    set
    some_Ind = 0
    where
    cond1=val1
    and some_Ind = 1
    and f_test(param1, param2) ='Y'
    If i have say total 5 rows in tableA and the some_Ind is set to 1 for 2 rows.
    Will this update stmt, call the funtion for all 5 rows ? and then update only the rows matching the condition?
    Because i am expecting this update stmt to call the function for only the 2 rows which has the some_Ind as set but i get the message printed out 5 times for 5 rows but it updates only 2 rows.
    Since this function f_test is very complex, i need to call it for only those rows to be updated.
    Please give your suggestions....thanx...

    I just gave the test function to display the two parameters.
    This function is displaying the messages for all the 5 rows and not for the 2 rows which match the condition.
    CREATE OR REPLACE FUNCTION f_test1 (param1IN VARCHAR2,param2 IN VARCHAR2)
    RETURN VARCHAR2 IS
    retInd varchar2(1);
    begin
    dbms_output.put_line('param1: '||param1);
    dbms_output.put_line(param2: '||param2);
    retInd := 'Y';
    DBMS_OUTPUT.PUT_LINE('Val of retInd:'||retInd);
    RETURN retInd;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('other exception ');
    RETURN 'N';
    END;

  • How to convert pl/sql block into single update statement

    Dear all gurus,
    I have pl/sql block mention below, Can I convert this pl/sql block to single update statement if possible?
    If not how to optimize this block?
    Pleaese suggest.
    thanks in advance.
    Vijay
    DECLARE
    CURSOR vt_mlr_cursor IS Select master_key, user4 from vt_mlr Where USER4 is not null;
    USERFIELD VARCHAR2(100);
    C1 VARCHAR2(3); /* this will return location of first space = 12 */
    C2 VARCHAR2(3); /* this will return location of second space = 20 */
    C3 VARCHAR2(3); /* this will return location of third space = 28 */
    C4 VARCHAR2(3); /* this will return location of forth space = 35 */
    Field1 VARCHAR2(40); /* this will return FTMYFLXA04W */
    Field2 VARCHAR2(10); /* this will return VPI0043 */
    Field3 VARCHAR2(10); /* this will return VCI0184 */
    Field4 VARCHAR2(10); /* this will return 005 */
    Field5 VARCHAR2(10); /* this will return 00001 */
    Field_2_n_3 VARCHAR2(25);
    key VARCHAR2(10);
    BEGIN
    FOR vt_mlr_record IN vt_mlr_cursor
    LOOP
    key := vt_mlr_record.master_key;
    USERFIELD := vt_mlr_record.user4;
    C1 := INSTR(vt_mlr_record.user4,' ',1,1); /* this will return location of first space = 12 */
    C2 := INSTR(vt_mlr_record.user4,' ',1,2); /* this will return location of second space = 20 */
    C3 := INSTR(vt_mlr_record.user4,' ',1,3); /* this will return location of third space = 28 */
    C4 := INSTR(vt_mlr_record.user4,' ',1,4); /* this will return location of forth space = 35 */
    Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1); /* this will return FTMYFLXA04W */
    Field2 := SUBSTR(vt_mlr_record.user4,C1+4,C2-C1-4); /* this will return VPI0043 */
    Field3 := SUBSTR(vt_mlr_record.user4,C2+4,C3-C2-4); /* this will return VCI0184 */
    Field4 := SUBSTR(vt_mlr_record.user4,C3+4,C4-C3-4); /* this will return 005 */
    Field5 := SUBSTR(vt_mlr_record.user4,C4+4,LENGTH(vt_mlr_record.user4)-C4-3); /* this will return 00001 */
    Field_2_n_3 := Field2 || '/' || Field3;
    /*DBMS_OUTPUT.PUT_LINE ('Current key is: ' || vt_mlr_record.master_key);*/
    UPDATE vt_mlr
    SET
    aggregator_clli = Field1,
    aggregator_vpi_vci = Field_2_n_3,
    aggregator_slot = Field4,
    aggregator_port = Field5
    WHERE
    master_key = vt_mlr_record.master_key;
    END LOOP;
    END;
    /

    Hi Vijay,
    Here's something to start with, you should be able to complete it.
    First, combine your select and update statements:
    update vt_mlr
       set aggregator_clli = field1
          ,aggregator_vpi_vci = field_2_n_3
          ,aggregator_slot = field4
          ,aggregator_port = field5
    where user4 is not null;Then put these two
    C1 := INSTR(vt_mlr_record.user4,' ',1,1); 
    Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1);into
    Field1 := SUBSTR(vt_mlr_record.user4,1,INSTR(vt_mlr_record.user4,' ',1,1) -1);And put it into the update statement, removing reference to record
    (I have also removed default values for position and occurrence in instr function):
    update vt_mlr
       set aggregator_clli = substr(user4, 1, instr(user4,' ') - 1)
          ,aggregator_vpi_vci = field_2_n_3
          ,aggregator_slot = field4
          ,aggregator_port = field5
    where user4 is not null; I think you can do the rest from here ;-)
    Regards
    Peter

  • Can I use a select and update statement in a single jsp file?

    I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
    note: I used a seperate table in BUY and SELL transaction
    After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
    select * from test, test1;
    update test
    set total_shares=total_shares-Stotal;
    where stock_code=Scode AND name_broker=Sbroker;
    Can i have both of these statements in the same jsp file in oder to update the buy table?
    Or can anyone suggest how can process that update?THANKS!
    --------------------

    Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?

  • Problem with update statement

    Hi, i have the following data
    document_seq_num, Country, LE, SOB
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    i want an update statement for every change in the document sequnce with the other combination..
    the seqence number should change.
    i tried to write a rank over partion and and sequence but when i am trying to update, this is always updating
    90000000 in first run, as it is in loop for all records it is updating the same. i want an
    increment to the sequence for every change in document_seq_num
    Can any one help me to correct this procedure
    create or replace PROCEDURE test is
    cursor cur_voc_ref
    IS SELECT a.document_seq_num,
    a.country, a.LE, a.SOB, 2009, Rank() over (partition by
    a.country, a.LE, a.SOB
    order by a.document_seq_num, a.country, a.LE, a.SOB)
    from (select distinct document_seq_num,
    country, LE, SOB,period_name
    from temp_tab
    where country= 'NL'
    and LE= '000320'
    and SOB=13
    order by SOB,LE,document_seq_num) a
    where
    a.country= 'NL'
    and a.LE= '000320'
    and a.SOB=13
    and substr(a.period_name,5,6) =substr(2009,3,4);
    v_base number;
    BEGIN
    FOR c_rec IN cur_voc_ref
    LOOP
    BEGIN
    select nvl(max(ggtsi.reference), substr(2009,3,2)*1000000) into v_base
    from temp_tab ggtsi;
    update temp_tab
    set reference= v_base
    where document_seq_num= c_rec.document_seq_num
    and country=c_rec.country
    and le=c_rec.le
    and sob=c_rec.sob;
    commit;
    END;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line( 'Exception in opening balance insert ' || SQLCODE || ' ' || SQLERRM );
    END;

    user11289444 wrote:
    Hi, i have the following data
    document_seq_num, Country, LE, SOB
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100037     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100038     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100039     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100040     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100041     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100042     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    33100043     NL     000320     13     
    i want an update statement for every change in the document sequnce with the other combination..
    the seqence number should change.
    i tried to write a rank over partion and and sequence but when i am trying to update, this is always updating
    90000000 in first run, as it is in loop for all records it is updating the same. i want an
    increment to the sequence for every change in document_seq_num
    Can any one help me to correct this procedure
    create or replace PROCEDURE test is
    cursor cur_voc_ref
    IS SELECT a.document_seq_num,
    a.country, a.LE, a.SOB, 2009, Rank() over (partition by
    a.country, a.LE, a.SOB
    order by a.document_seq_num, a.country, a.LE, a.SOB)
    from (select distinct document_seq_num,
    country, LE, SOB,period_name
    from temp_tab
    where country= 'NL'
    and LE= '000320'
    and SOB=13
    order by SOB,LE,document_seq_num) a
    where
    a.country= 'NL'
    and a.LE= '000320'
    and a.SOB=13
    and substr(a.period_name,5,6) =substr(2009,3,4);
    v_base number;
    BEGIN
    FOR c_rec IN cur_voc_ref
    LOOP
    BEGIN
    select nvl(max(ggtsi.reference), substr(2009,3,2)*1000000) into v_base
    from temp_tab ggtsi;
    update temp_tab
    set reference= v_base
    where document_seq_num= c_rec.document_seq_num
    and country=c_rec.country
    and le=c_rec.le
    and sob=c_rec.sob;
    commit;
    END;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line( 'Exception in opening balance insert ' || SQLCODE || ' ' || SQLERRM );
    END;Hi,
    I suggest you to add a column to preserve current RANK value for all rows, <preserve_rank> for example, and
    when you add the new rows you will update your <preserve_rank> but you must pay attention to have the same value for
    document_seq_num, with other words you may insert yours rows in a batch like this:
    -- first update preserve_rank with RANK function
    declare
    v_doc_seq_num numeric;
    begin
    v_doc_seq_num:=33100040;
    -- note !!!
    -- put all into a valid sql command
    -- and apply execute immediate
    insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
    insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
    insert into temp_tab(document_seq_num, country, le, sob,Period_name)values(v_doc_seq_num, 'NL', '000320', 13,'APR-09');
    -- update preserve_rank
    update temp_tab x  set x.preserve_rank = (Select max(preserve_rank) from temp_tab y
                                              where y.document_seq_num=v_doc_seq_num) old_rank + 1)
    where (prserve_rank is null) and x.document_seq_num=v_doc_seq_num;
    end;  I know it's a lost a memory but the trigger is the last solution who can give us a nightmare.
    Regards,
    Ion
    Edited by: user111444777 on Sep 25, 2009 11:12 AM
    Edited by: user111444777 on Sep 25, 2009 11:35 AM

  • SQL Update statement taking too long..

    Hi All,
    I have a simple update statement that goes through a table of 95000 rows that is taking too long to update; here are the details:
    Oracle Version: 11.2.0.1 64bit
    OS: Windows 2008 64bit
    desc temp_person;
    Name                                                                                Null?    Type
    PERSON_ID                                                                           NOT NULL NUMBER(10)
    DISTRICT_ID                                                                     NOT NULL NUMBER(10)
    FIRST_NAME                                                                                   VARCHAR2(60)
    MIDDLE_NAME                                                                                  VARCHAR2(60)
    LAST_NAME                                                                                    VARCHAR2(60)
    BIRTH_DATE                                                                                   DATE
    SIN                                                                                          VARCHAR2(11)
    PARTY_ID                                                                                     NUMBER(10)
    ACTIVE_STATUS                                                                       NOT NULL VARCHAR2(1)
    TAXABLE_FLAG                                                                                 VARCHAR2(1)
    CPP_EXEMPT                                                                                   VARCHAR2(1)
    EVENT_ID                                                                            NOT NULL NUMBER(10)
    USER_INFO_ID                                                                                 NUMBER(10)
    TIMESTAMP                                                                           NOT NULL DATE
    CREATE INDEX tmp_rs_PERSON_ED ON temp_person (PERSON_ID,DISTRICT_ID) TABLESPACE D_INDEX;
    Index created.
    ANALYZE INDEX tmp_PERSON_ED COMPUTE STATISTICS;
    Index analyzed.
    explain plan for update temp_person
      2  set first_name = (select trim(f_name)
      3                    from ext_names_csv
      4                               where temp_person.PERSON_ID=ext_names_csv.p_id
      5                               and   temp_person.DISTRICT_ID=ext_names_csv.ed_id);
    Explained.
    @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 3786226716
    | Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT            |                | 82095 |  4649K|  2052K  (4)| 06:50:31 |
    |   1 |  UPDATE                     | TEMP_PERSON    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL         | TEMP_PERSON    | 82095 |  4649K|   191   (1)| 00:00:03 |
    |*  3 |   EXTERNAL TABLE ACCESS FULL| EXT_NAMES_CSV  |     1 |   178 |    24   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("EXT_NAMES_CSV"."P_ID"=:B1 AND "EXT_NAMES_CSV"."ED_ID"=:B2)
    Note
       - dynamic sampling used for this statement (level=2)
    19 rows selected.By the looks of it the update is going to take 6 hrs!!!
    ext_names_csv is an external table that have the same number of rows as the PERSON table.
    ROHO@rohof> desc ext_names_csv
    Name                                                                                Null?    Type
    P_ID                                                                                         NUMBER
    ED_ID                                                                                        NUMBER
    F_NAME                                                                                       VARCHAR2(300)
    L_NAME                                                                                       VARCHAR2(300)Anyone can help diagnose this please.
    Thanks
    Edited by: rsar001 on Feb 11, 2011 9:10 PM

    Thank you all for the great ideas, you have been extremely helpful. Here is what we did and were able to resolve the query.
    We started with Etbin's idea to create a table from the ext table so that we can index and reference easier than an external table, so we did the following:
    SQL> create table ext_person as select P_ID,ED_ID,trim(F_NAME) fst_name,trim(L_NAME) lst_name from EXT_NAMES_CSV;
    Table created.
    SQL> desc ext_person
    Name                                                                                Null?    Type
    P_ID                                                                                         NUMBER
    ED_ID                                                                                        NUMBER
    FST_NAME                                                                                     VARCHAR2(300)
    LST_NAME                                                                                     VARCHAR2(300)
    SQL> select count(*) from ext_person;
      COUNT(*)
         93383
    SQL> CREATE INDEX EXT_PERSON_ED ON ext_person (P_ID,ED_ID) TABLESPACE D_INDEX;
    Index created.
    SQL> exec dbms_stats.gather_index_stats(ownname=>'APPD', indname=>'EXT_PERSON_ED',partname=> NULL , estimate_percent=> 30 );
    PL/SQL procedure successfully completed.We had a look at the plan with the original SQL query that we had:
    SQL> explain plan for update temp_person
      2  set first_name = (select fst_name
      3                    from ext_person
      4                               where temp_person.PERSON_ID=ext_person.p_id
      5                               and   temp_person.DISTRICT_ID=ext_person.ed_id);
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 1236196514
    | Id  | Operation                    | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |                | 93383 |  1550K|   186K (50)| 00:37:24 |
    |   1 |  UPDATE                      | TEMP_PERSON    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL          | TEMP_PERSON    | 93383 |  1550K|   191   (1)| 00:00:03 |
    |   3 |   TABLE ACCESS BY INDEX ROWID| EXTT_PERSON    |     9 |  1602 |     1   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN          | EXT_PERSON_ED  |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("EXT_PERSON"."P_ID"=:B1 AND "RS_PERSON"."ED_ID"=:B2)
    Note
       - dynamic sampling used for this statement (level=2)
    20 rows selected.As you can see the time has dropped to 37min (from 6 hrs). Then we decided to change the SQL query and use donisback's suggestion (using MERGE); we explained the plan for teh new query and here is the results:
    SQL> explain plan for MERGE INTO temp_person t
      2  USING (SELECT fst_name ,p_id,ed_id
      3  FROM  ext_person) ext
      4  ON (ext.p_id=t.person_id AND ext.ed_id=t.district_id)
      5  WHEN MATCHED THEN
      6  UPDATE set t.first_name=ext.fst_name;
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 2192307910
    | Id  | Operation            | Name         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | MERGE STATEMENT      |              | 92307 |    14M|       |  1417   (1)| 00:00:17 |
    |   1 |  MERGE               | TEMP_PERSON  |       |       |       |            |          |
    |   2 |   VIEW               |              |       |       |       |            |          |
    |*  3 |    HASH JOIN         |              | 92307 |    20M|  6384K|  1417   (1)| 00:00:17 |
    |   4 |     TABLE ACCESS FULL| TEMP_PERSON  | 93383 |  5289K|       |   192   (2)| 00:00:03 |
    |   5 |     TABLE ACCESS FULL| EXT_PERSON   | 92307 |    15M|       |    85   (2)| 00:00:02 |
    Predicate Information (identified by operation id):
       3 - access("P_ID"="T"."PERSON_ID" AND "ED_ID"="T"."DISTRICT_ID")
    Note
       - dynamic sampling used for this statement (level=2)
    21 rows selected.As you can see, the update now takes 00:00:17 to run (need to say more?) :)
    Thank you all for your ideas that helped us get to the solution.
    Much appreciated.
    Thanks

  • Sql Update Statement (complex)

    Hi ,
    A very good morning to all.
    I am stuck in a problem , and i really hope for solutiion.
    I have a dimension table (DIM_CAR) for which i need to write a update statement.
    My table structure is :
    C_ID           Startdate                       EndDate
    7546343    2012-05-29 00:00:00    NULL
    7546343    2012-05-18 00:00:00    2012-05-29 00:00:00
    7546343    2012-05-14 00:00:00    2012-05-18 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-10 00:00:00
    7546343    2012-05-10 00:00:00    2012-05-14 00:00:00
    7546343    2012-03-22 00:00:00    2012-03-22 00:00:00
    7546343    2012-03-15 00:00:00    2012-03-22 00:00:00
    7546343    2012-02-02 00:00:00    2012-03-15 00:00:00
    7546343    2012-01-31 00:00:00    2012-02-02 00:00:00
    Now the scenario is Whenever any update comes in car , then it closes the previous record and open a new record(SCD)
    For e.g the 1st update comes on 2012-02-02 , so it closes the last record (by putting 2012-02-02) in end date and open a new record by putting 2012-02-02 in startdate. Then update comes in 2012-03-15 and so on. The last record is for 2012-05-29 which is
    still open as there is no update after that,
    so whenever any update come it opens a new record with startdate value is extract date and enddate value NULL and closes the previous. Then  after another update , that NULL value is replace by the new date and another record opens.
    My prob is if you will closely analyse the dates , then there are some records missing in the above table due to which there are discrepencies in dates.
    E.g. If u see the 6th row, startdate is 2012-03-22 and enddate is also 2012-03-22. But here in this case the enddate should be 2012-05-10(which is next update)
    I need to write a sql script to update enddates with the latest update startdate in my table. I have 60000 of C_id which are affected.
    COULD ANYONE plz Help.. I knw its difficult but u can give a try ..........Plz ask if anyone requires more info.
    Abhishek

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have a dimension table (DIM_CAR) for which I need to write a update statement. My table structure is : <<
    NO! This is a picture of the data; it is not DDL! Is this what you would have posted if you had manners? 
    CREATE TABLE Foobars
    (c_id CHAR(7) NOT NULL, 
     foo_start_date DATE NOT NULL, 
     PRIMARY KEY (c_id, foo_start_date), -- my guess!!
     CHECK (foo_start_date < foo_end_date),-- another guess! 
     foo_end_date DATE);
    INSERT INTO Foobar
    VALUES 
    ('7546343', '2012-05-29', 'NULL), 
    ('7546343', '2012-05-18', '2012-05-29'), 
    ('7546343', '2012-05-14', '2012-05-18'), 
    ('7546343', '2012-05-10', '2012-05-10'), 
    ('7546343', '2012-05-10', '2012-05-14'), 
    ('7546343', '2012-03-22', '2012-03-22'), 
    ('7546343', '2012-03-15', '2012-03-22'), 
    ('7546343', '2012-02-02', '2012-03-15'), 
    ('7546343', '2012-01-31', '2012-02-02');
    Now the scenario is Whenever any update comes in car, then it closes the previous record [sic: rows are not records! Please learn basic terms] and open a new record [sic](SCD). 
    What is “SCD” and why do you think it is meaningful to us? Here is an article on this topic. 
    Modifying Contiguous Time Periods
    This article explains how to modify contiguous time periods that were described in Joe Celko’s article 'Contiguous Time Periods in SQL'.  Joe describes the table itself that he calls the 'Kuznetsov History Table'. He explains how it is used to store contiguous
    time intervals with constraint to ensure that the date periods really are contiguous, The editor suggested that I give a brief description of how to modify the data in the History table as this may not be entirely obvious.
    When trusted constraints enforce data integrity, the data is guaranteed to be valid at the end of any statement, even if it is not committed. When we modify contiguous time periods, in order to get from one valid state to another we may need to insert a row
    and update another one, or we may need to delete a row and update another one. This is one of those cases when MERGE really shines – it allows us to get from one valid state to another in one statement, inserting, updating, and deleting rows as needed.
    CREATE TABLE Tasks
    (task_id INT NOT NULL, 
     task_score INTEGER NOT NULL, 
     current_start_date DATE NOT NULL, 
     current_end_date DATE NOT NULL, 
     previous_end_date DATE NULL, 
     CONSTRAINT PK_Tasks_task_id_current_end_date 
     PRIMARY KEY (task_id, current_end_date), 
     CONSTRAINT UNQ_Tasks_task_id_previous_end_date 
      UNIQUE (task_id, previous_end_date), 
     CONSTRAINT FK_Tasks_task_id_previous_end_date 
      FOREIGN KEY (task_id, previous_end_date) 
      REFERENCES Tasks (task_id, current_end_date), 
     CONSTRAINT CHK_Tasks_previous_end_date_NotAfter_current_start_date 
      CHECK (previous_end_date <= current_start_date), 
     CONSTRAINT CHK_Tasks_current_start_date_Before_current_end_date 
      CHECK (current_start_date < current_end_date)
    Some Easy Modifications.
    It is easy to begin a new series of time periods
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES (1, 100, '2010-1002', '2010-1023', NULL),
           (1, 80, '2010-1023', '2010-11-03', '2010-1023');  
     It is just as easy to continue adding periods to the end of the series.
    INSERT INTO Tasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date)
    VALUES(1, 98, '2010-11-20', '2010-11-25', '2010-11-03'),
          (1, 75, '2010-11-26', '2010-11-27', '2010-11-25');
    Deleting one or more rows from the end is just as easy, and we shall skip the example. As we have seen, it is easy to perform typical, the most common operations against history of periods.
    However, some other operations are less easy and need more explanations. Now that we have enough test data, let us move on to more complex examples. Here is the test data at this moment: 
    Adding periods to the beginning.
    Each series of periods has exactly one first period – this is enforced by the following constraint: Unique_task_id_and_previous_end_date
    As a result, when we are inserting one or more periods to the beginning of the series, we have to update the period that used to be the first, as follows:
    MERGE INTO Tasks 
    USING (VALUES (1, 98, '2009-03-01', '2009-03-06', NULL),
                  (1, 100, '2010-10-02', '2010-10-23', '2009-03-06') 
           ) AS Source (task_id, task_score, current_start_date, current_end_date, previous_end_date)
       ON Tasks.task_id = Source.task_id
           AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED 
    THEN UPDATE
         SET task_score = Source.task_score, 
             current_start_date = Source.current_start_date, 
             current_end_date = Source.current_end_date, 
             previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date)
     VALUES (Source.task_id, Source.task_score, Source.current_start_date,
             Source.current_end_date, Source.previous_end_date); 
    Now we will verify that our test data looks as expected, with a new row at the beginning, and previous_end_date column is modified to point to the new row for the row that used to be the first before this modification:
    We are also going to discuss some other scenarios, such as adding/deleting periods in the middle of the series. In all these cases we shall be using MERGE, and the DML looks quite similar, so let us wrap it up in a stored procedure.
    CREATING A STORED PROCEDURE
    The following code implements this merging functionality with a stored procedure that uses a table to hold teh new rows:
    CREATE TABLE NewTasks
    (task_id INTEGER NOT NULL, 
    task_score INTEGER NOT NULL, 
    current_start_date DATE NOT NULL, 
    current_end_date DATE NOT NULL, 
    previous_end_date DATE NULL,
    deletion_flg CHAR(1));
    CREATE PROCEDURE MergeNewTasks
    AS BEGIN 
    MERGE INTO Tasks 
    USING (SELECT task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg
             FROM NewTasks) AS Source
       ON Tasks.task_id = Source.task_id
          AND Tasks.current_start_date = Source.current_start_date
    WHEN MATCHED AND deletion_flg = 'Y'
    THEN DELETE
    WHEN MATCHED 
    THEN UPDATE SET
         task_score = Source.task_score, 
         current_start_date = Source.current_start_date, 
         current_end_date = Source.current_end_date, 
         previous_end_date = Source.previous_end_date
    WHEN NOT MATCHED 
    THEN INSERT (task_id, task_score, current_start_date, current_end_date, previous_end_date) 
     VALUES (Source.task_id, Source.task_score, Source.current_start_date, Source.current_end_date, Source.previous_end_date);
    END; 
    Let us use this stored procedure.
    Filling a gap in the middle of the series
    The following code fills the gap on November 25th.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'N'),
     (1, 80, '2010-11-26', '2010-11-27', '2010-11-26', 'N');
    EXEC MergeNewTasks NewTasks = NewTasks;  
    Here is the data after this modification, with a period added in the middle fo the series:
    Deleting a period in the middle of the series
    The following code deletes the period added in the previous example.
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, 
        previous_end_date, deletion_flg)
    VALUES (1, 75, '2010-11-25', '2010-11-26', '2010-11-25', 'Y'),
           (1, 80, '2010-11-26', '2010-11-27', '2010-11-25', 'N');
    EXEC MergeNewTasks;  
    Here is the data after this modification:
    Inserting two periods in the middle, and adjusting an exaisting period to make room for them. This is the last and most complex example involving our stored procedure:
    CREATE TABLE NewTasks (..);
    INSERT INTO NewTasks
      (task_id, task_score, current_start_date, current_end_date, previous_end_date, deletion_flg)
    VALUES (1, 98, '2010-11-20', '2010-11-22', '2010-11-03', 'N'), 
           (1, 75, '2010-11-22', '2010-11-23', '2010-11-22', 'N'),
           (1, 98, '2010-11-23', '2010-11-25', '2010-11-23', 'N');
    EXEC MergeNewTasks; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • SQL UPDATE statement in MS Excel

    Hi All,
    I have a request to perform a column update in ap_invoices_all table. There are around 1000 rows to be updated. The input is in the form of MS Excel.
    Can somebody suggest how to make an update statement using MS Excel.
    My query using excel should look like below:
    UPDATE AP_INVOICES_ALL
    SET description = '',
    last_update_date = ,
    last_updated_by =
    WHERE org_id =
    AND vendor_site_id =
    AND invoice_num = ''
    Regards,
    Radhika.

    >
    Can somebody suggest how to make an update statement using MS Excel.
    >
    as a way:
    -- create heterogeneous service for ms excel
    -- create dblink for this service
    -- do update like
    UPDATE AP_INVOICES_ALL
       SET description = (
                              with t as
                                select value_for_description,                                   
                                       org_id,
                                       vendor_site_id,
                                       invoice_num
                                 from sheet@dblink_to_excel
                              select t.value_for_description
                                from t t
                               where s.org_id = t.org_id
                                     and s.vendor_site_id = t.vendor_site_id
                                     and s.invoice_num = t.invoice_num
                            )other way:
    -- create heterogeneous service for ms excel
    -- create dblink for this service
    -- insert for some temporary table
    -- do update like above but based on temp table

  • How to use rownum=2 in update statement  ?

    Hi all,
    we are migrating the data from mainframe to oracle. migration team extracted the data into flat file. we are using this flat file to load in oracle.Finacle have menu option to load data from flat file to corresponding oracle tables.whenever i given this flat file to Menu it will give error report like below if any rows have error.
    here "A/c. Opening Matrix" is the error.
    error report:-
    A/c. Opening Matrix
    The Above Error Was For record No: 1
    A/c. Opening Matrix
    The Above Error Was For record No: 2
    we are extracting and storing all the error message and corresponding record no in shell script as below.
    err_msg=`echo ${error_msg[i]}`
    rec_num=`echo ${error_msg[i]}| cut -d: -f2`
    we need to update the upload status either upload success or failure and error message in upload history table. iam writing the update statement as below.
    update statement:-
    update upld_hist set upld_status='ERR' ,upld_err='$err_msg' where rownum=$rec_num;
    This is statement is updating only for rownum=1. other than this it is not updating the table. Please suggest me how to update the rows based on rownum?
    Thanks,
    Venkat Vadlamudi

    868591 wrote:
    Hi all,
    we are migrating the data from mainframe to oracle. migration team extracted the data into flat file. we are using this flat file to load in oracle.Finacle have menu option to load data from flat file to corresponding oracle tables.whenever i given this flat file to Menu it will give error report like below if any rows have error.
    here "A/c. Opening Matrix" is the error.
    error report:-
    A/c. Opening Matrix
    The Above Error Was For record No: 1
    A/c. Opening Matrix
    The Above Error Was For record No: 2
    we are extracting and storing all the error message and corresponding record no in shell script as below.
    err_msg=`echo ${error_msg[i]}`
    rec_num=`echo ${error_msg[i]}| cut -d: -f2`
    we need to update the upload status either upload success or failure and error message in upload history table. iam writing the update statement as below.
    update statement:-
    update upld_hist set upld_status='ERR' ,upld_err='$err_msg' where rownum=$rec_num;
    This is statement is updating only for rownum=1. other than this it is not updating the table. Please suggest me how to update the rows based on rownum?
    Thanks,
    Venkat VadlamudiUse Analytic ROW_NUMBER() ..
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions156.htm#i86310

  • UPDATE statement in procedure

    Hi,
    I'm having trouble getting my SP to work. I've searched this forum for a similar post, but haven't found it.
    Can anyone please let me know what I'm doing wrong here?
    Thanks!
    CREATE OR REPLACE PROCEDURE updadminproc
    (pdate   IN CHANGE_CONTROL_ADMIN.CLOSEDATE%TYPE,
    pact   IN CHANGE_CONTROL_ADMIN.ACTIVE%TYPE,
    pstat1   IN CHANGE_CONTROL_ADMIN.STATUS1%TYPE,
    pstat2   IN CHANGE_CONTROL_ADMIN.STATUS2%TYPE,
    padmcomm   IN CHANGE_CONTROL_ADMIN.ADM_NOAPROVE%TYPE)
    (cctrlid IN NUMBER)
    IS
    BEGIN
      -- UPDATE STATEMENT
    UPDATE CHANGE_CONTROL_ADMIN
       SET CLOSEDATE = pdate, ACTIVE = pact, STATUS1 = pstat1, STATUS2 = pstat2, ADM_NOAPROVE = padmcomm
       WHERE CHANGE_CTRL_ID = cctrlid;
    COMMIT;
    END updadminproc;
    /Here are the errors I get that it's showing:
    LINE/COL ERROR
    7/2      PLS-00103: Encountered the symbol "(" when expecting one of the
             following:
             ; is with authid as cluster order using external
             deterministic parallel_enable pipelined
    8/2      PLS-00103: Encountered the symbol "IS" when expecting one of the
             following:
             returnMessage was edited by:
    user515689

    when I change it accordingly as to how you suggest, the procedure (in SQL Plus) gets created just fine, but then I get an Oracle error when calling the SP.
    PLS-00306: wrong number or types of arguments in call to 'UPDADMINPROC'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
            at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
            at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)Any ideas? Since it reads wrong no. of arguments?
    My Java call statement looks like the following:
    CallableStatement cstmt = connection.prepareCall("{call updadminproc (?,?,?,?,?)}");
       cstmt.setDate(1,cldt);
       cstmt.setInt(2,actboxval);
       cstmt.setString(3,status1);
       cstmt.setString(4,status2);
       cstmt.setString(5,fincomments);
       cstmt.executeUpdate();I mean, I'm not trying to update the ID no., just associate the record with the ID number (cctrlid).
    Thanks.
    Ok, I got it....even though not updating the ID # itself, I had to add it to the cstmt object.
    As in ....
    cstmt.setString(5,fincomments);
    cstmt.setInt(6,ctid2);
    cstmt.executeUpdate();
    Message was edited by:
    user515689

  • Using Escape character in UPDATE statement

    SELECT REPLACE
              ( REPLACE
                     ( REPLACE( REPLACE( REPLACE( REPLACE( BODY, '<STARTOFLINK>' )
                                                , '<ENDOFLINK>' )
      FROM ARTICLEI need to use the above in an UPDATE statement to remove some HTML tags from a CLOB column. However when I run the script it asks for the substitution variables for the '&' characters. I've tried "ESCAPE '\'" but I think you can only use that with a like operand.
    Any suggestions?
    Message was edited by:
    Terrible
    As you can see the HTML tags have been converted in this post!! I'm trying to remove:
    & amp;
    & quot;
    & ndash;
    & #039;

    This may help;
    SQL> create table t (col1 varchar2(200))
    Table created.
    SQL> insert into t values('<STARTOFLINK>')
    PL/SQL executed.
    SQL> insert into t values('<ENDOFLINK>')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || 'amp;')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || 'quot;')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || 'ndash;')
    PL/SQL executed.
    SQL> insert into t values(chr(38) || '#039;')
    PL/SQL executed.
    SQL> insert into t values('<STARTOFLINK>link<ENDOFLINK> '
                       || '  AMP:' || chr(38) || 'amp;'
                       || '  DQT:' || chr(38) || 'quot;'
                       || '  DASH:'|| chr(38) || 'ndash;'
                       || '  SQT:' || chr(38) || '#039;')
    PL/SQL executed.
    SQL> select * from t
    col1                                                                           
    <STARTOFLINK>                                                                  
    <ENDOFLINK>                                                                    
    <STARTOFLINK>link<ENDOFLINK>   AMP:&  DQT:"  DASH:–  SQT:' 
    7 rows selected.
    SQL> select regexp_replace(
              regexp_replace(
                 regexp_replace(
                    regexp_replace(
                       regexp_replace(col1, '<.*OFLINK>',NULL),
                    chr(38) || 'amp;', chr(38)),
                 chr(38) || 'quot;', chr(34)),
              chr(38) || 'ndash;', chr(45)),
           chr(38) || '#039;', chr(39))
    new_col from t
    NEW_COL                                                                        
       AMP:&  DQT:"  DASH:-  SQT:'                                                 
    7 rows selected.Message was edited by:
    MScallion
    The SELECT * values were not as they are displayed due to HTML conversions.

  • Replication update statement takes long time

    Hi Replication experts,
    I have a issue and please suggest if my understanding and solution is correct.
    We have a transactional replication setup for data warehouse, from today morning replication got huge latency so when I looked into it I saw the "sp_MSupd_< tablename >" was running for very long time and by this time it was running for 9 hours
    still no data was updated, Latency went very high. What we feel is that the index maintenance was not done in subscriber also it was not replicated too. So due to high fragmentation the update statement could take very long.
    As there was no error message or blocks found all we see is the update taking very long. So to avoid this we are planning to remove the index, as this is just data warehouse index maintenance is not required by removing we can gain some space too. Is this a
    good Idea to implement?
    When we ran profiler nothing was found, no error or alert logged.
    Please let me know your suggestions
    Thanks
    Best Regards Moug

    Hi All,
    The Issue we found to be is that a day before, new column was added to the table and 9000 rows were updated ... This caused the distributor to slow down the update operation as the index in subscriber(15 million rows) was updating every time  a row
    is updated.. So we suspect that adding a new column and updating it at the same time is the culprit..
    But still am not convinced as per my understanding the distributor operates by comparing the primary key of publisher that was changed with the primary key of the subscriber and apply those change.. If that is the case why should it worry about the new column
    added or the number of updates..
    Also one strange thing is another table was also lagging behind in its operation ,though that table was updated with just 18 rows.. So in a nutshell the update operation was totally down by distributor operation on that day..
    Can someone please shed some light on this, Replication is my favorite topic but now I got fear of it.. after failing to know what could be issue... 
    Best Regards Moug

Maybe you are looking for