Update Multiple Columns when concerned about redo/undo log sizes.

Hi ,
I have update statements that updates multiple columns at once if any of them is changed. What I see that even though the value of column is not changed it still increases the redo size.
Below is a sample code similar to the ones in my code. Basically I check whether there is a difference in any of the columns to be updated and update all of them.
Is there a way to improve redo log size without splitting the update statement for every column that I will be updating. Redo/Undo log size is a concern for us..
  For i In 1.rec.Count Loop
    Update employees e
       Set e.first_name = rec(i).first_name, e.last_name = rec(i).last_name
     Where e.first_name != rec(i).first_name
        Or e.last_name != rec(i).last_name;
  End Loop;My database is 10g.

Muhammed Soyer wrote:
Redo/Undo log size is a concern for us..You are worried about the wrong thing.
If you are concerned about the amount of undo and redo, you should be less concerned about the small diffrence between updating 1 or 3 columns and remove the loop that is contributing to a massive increase in both undo and redo.
Re: global temporary table row order
Name                                  Run1        Run2        Diff
STAT...undo change vector size     240,500   6,802,736   6,562,236
STAT...redo size                 1,566,136  24,504,020  22,937,884Run2 shows what adding a loop to a regular SQL statement will do to undo and redo. It made the redo used 15 times greater and the undo almost 30 times greater.

Similar Messages

  • UPDATE multiple columns with conditional SET parameters

    I have a procedure that updates multiple columns of a table using the procedure's parameter. Is it possible to have one update statement with conditional SET parameter?
    CREATE TABLE TEMP
    (POL_NUM NUMBER,
    OED DATE,
    TERM NUMBER,
    TRANS_CD CHAR(2));
    INSERT INTO TEMP VALUES (1, '1 AUG 2009', 12, 'NB');
    INSERT INTO TEMP VALUES (2, '4 AUG 2009', 12, 'XL');
    INSERT INTO TEMP VALUES (3, '2 AUG 2009', 12, 'RN');
    COMMIT;
    CREATE OR REPLACE PROCEDURE TMP_PROC (
      pPOL_NUM NUMBER,
      pOED IN DATE,
      pTERM IN NUMBER,
      pTRANS_CD CHAR2)
    AS
    BEGIN
      IF pOED IS NOT NULL THEN
        UPDATE TEMP SET OED = pOED WHERE POL_NUM = pPOL_NUM;
      END IF;
      IF pTERM IS NOT NULL THEN
        UPDATE TEMP SET TERM = pTERM WHERE POL_NUM = pPOL_NUM;
      END IF;
      IF pTRAN_CD IS NOT NULL THEN
        UPDATE TEMP SET TRANS_CD = pTRANS_CD WHERE POL_NUM = pPOL_NUM;
      END IF;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN
         NULL;
    END;Is it possible to replace multiple IFs from the code to have only one UPDATE statement with condition that update the column only if the passed parameter is not null? In real scenario I have more than 3 columns and I don't want to write many IF blocks.
    Please help Gurus!!
    Edited by: Kuul13 on Sep 18, 2009 1:26 PM

    Hi,
    You certainly don't want to issue separate UPDATE statements for every column; that will be really inefficent.
    SQL has several ways to implement IF-THEN-ELSE logic. CASE is the most versatile, but NVL will do everything you need for this job. You can use one of those to set a column to itself (and therefore not really update that column) when appropriate.
    For example:
    CREATE OR REPLACE PROCEDURE TMP_PROC (
      pPOL_NUM   IN       NUMBER,
      pOED          IN   DATE,
      pTERM          IN   NUMBER,
      pTRANS_CD  IN       CHAR
    AS
    BEGIN
         UPDATE  temp
         SET     oed      = NVL (poed,       oed)
         ,     term      = NVL (pterm,       term)
         ,     trans_cd = NVL (ptrans_cd, trans_cd)
         WHERE     pol_num      = ppol_num;
      COMMIT;     -- Maybe
    END    tmp_proc;"EXCEPTION WHEN OTHERS THEN NULL" is almost always a bad idea. If there's an error, don't you want to know about it? Shouldn't you at least log a message in a warnings table or something?
    Think careflully about whether or not you want to COMMIT every time you call this procedure.
    Just as it's inefficient to issue a separate UPDATE statement for every column, it's also inefficient to issue a separate UPDATE statement for every row. If efficiency is important, it should be possible to UPDATE several rows in a single UPDATE statement, using NVL (or CASE, or COALESCE, or NULLIF, or NVL2, or ...).
    This was a very well-written question! Thanks for providing the CREATE TABLE and INSERT statements, and such a clear explanation.

  • How to update multiple columns from different tables using cursor.

    Hi,
    i have two tables test1 and test2. i want to udpate the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
    I have a code written as follows :
    DECLARE
    v_mydept1 TEST1.DEPT_CD%TYPE;
    v_mydept2 TEST2.DEPT_CD%TYPE;
    CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
    BEGIN
    OPEN C1;
         LOOP
              FETCH C1 INTO v_mydept1,v_mydept2;
              EXIT WHEN C1%NOTFOUND;
              UPDATE TEST2 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
              UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
         END LOOP;
         COMMIT;
    END;
    The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
    It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
    I am not sure what is the exact problem when we want to update multiple columns of different tables.
    Can anyone help me on this ?

    oops my mistake.....typo mistake...it should have been as follows --
    UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
    UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
    Now here is the upated PL/SQL code where we are trying to update columns of different tables --
    DECLARE
    v_mydept1 TEST1.DEPT_CD%TYPE;
    v_mydept2 TEST2.DEPT_CD%TYPE;
    CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
    BEGIN
    OPEN C1;
    LOOP
    FETCH C1 INTO v_mydept1,v_mydept2;
    EXIT WHEN C1%NOTFOUND;
    UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
    UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
    END LOOP;
    COMMIT;
    END;
    Please let us know why it is not updating by using using CURRENT OF

  • Update multiple columns with single update statement..

    HI all,
    i am reading the columns value from different table but i want to update it with signle update statement..
    such as how to update multiple columns (50 columns) of table with single update statement .. is there any sql statement available i know it how to do with pl/sql..

    As I understood, may be this. Here i am updating ename,sal, comm columns all at once.
    SQL> select * from emp where empno=7369;
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17/12/1980 12:00:00        800                    20
    SQL> UPDATE emp
      2     SET ename = lower (ename),
      3         sal = sal + 1000,
      4         comm = 100
      5   WHERE empno = 7369;
    1 row updated.
    SQL> select * from emp where empno=7369;
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 smith      CLERK           7902 17/12/1980 12:00:00       1800        100         20
    SQL> UPDATE emp
      2     SET ename = (SELECT 'ABCD' FROM DUAL),
      3         sal = (SELECT 1000 FROM DUAL),
      4         comm = (SELECT 100 FROM DUAL)
      5   WHERE empno = 7369;
    1 row updated.

  • Merge statement - update multiple columns from a single sub-select

    Is it possible to write in 10gR2, a MERGE statement, with UPDATE for multiple columns from a single sub_select?
    like this:
    MERGE INTO tableA
    using ( select * from temp) tmp
    on( tableA. col1 = tmp.col1)
    when matched then
    update set  ( tableA.col5,
                       tableA.col6,
                       tableA.col7) = ( select sum(col2), sum(col3), sum(col5)
                                                                                 from tableX
                                                                                where tableX.col1 = tableA.col1...)

    Hi,
    The USING clause is not a sub-query, so it can't reference columns from tables that are not in it.
    Include tableA in the USING clause if you really need to refer to it there. (It's not obvious that you do.)
    As always, it helps if you post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data (In the case of a DML statement, such as MERGE, this will be the state of the tables when everything is finished.)
    (4) Your best attempt so far (formatted)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, tables in scott schema, or views in the data dictionary), then you can omit (2).
    Formatted tabular output is okay for (3).

  • Updating a column when button  pressed

    Hello,
    I have a ADF master detail table and in the detail table and I would like to add a button. When user select a row and presses the button, I need to update a column value to 'Y'. How can I do this?
    I need to have a Yes or No prompt as welll before it gets updated in the db table.
    How can I acheive this.
    Thanks a lot.

    Hi,
    if you use ADF, on the button action method, access the ADF biinding, get a hande to the iterator and call getCurrentRow() on it. The set the attribute that represents the column and set Yes or No to it.
    Make sure you use PPR to refresh the table when teh button is pressed
    Frank

  • Linq selecting multiple columns when using anonymous types using Sum multiple columns

    I have a list with multiple columns where I need to sum a list of columns for each row into a new column (not 100% sure if there is another way to sum other than I have done it). Problem I'm having is being able to select more than just column I'm creating
    used from summing the other column and the Key. Below will produce a row with the CustomerId and the total of all the months.
    CustomerId
    Total
    12345
    2500.00
    12346
    3000.00
    But let's say I have a row called Name in "history"--how can display it in the query results as below.  I'm unable to reference anything but the key.
    CustomerId
    Total
    Name
    12345
    2500.00
    John Smith
    12346
    3000.00
    May Allen
    var list = history
    .GroupBy(g => g.CustomerId)
    .Select(sg =>
    new
    Key = lg.Key,
    SumTotal = sg.Sum(x => x.month_01)
    + sg.Sum(x => x.month_02)
    + sg.Sum(x => x.month_03)
    + sg.Sum(x => x.month_04)
    + sg.Sum(x => x.month_05)
    + sg.Sum(x => x.month_06)
    + sg.Sum(x => x.month_07)
    + sg.Sum(x => x.month_08)
    + sg.Sum(x => x.month_09)
    + sg.Sum(x => x.month_10)
    + sg.Sum(x => x.month_11)
    + sg.Sum(x => x.month_12)

    Hi
    ajl7519,
    I have tested on my side,  please check my code. 
    InitializeComponent();
    AuctionItems = new List<AuctionItem>() {
    new AuctionItem() { Category = "Car", CurrentPrice = "100", Description = "100", SpecialFeatures = "100", StartDate = 1, StartPrice = 1 },
    new AuctionItem() { Category = "Car", CurrentPrice = "100", Description = "100", SpecialFeatures = "100", StartDate = 2, StartPrice = 2 },
    new AuctionItem() { Category = "Car", CurrentPrice = "100", Description = "100", SpecialFeatures = "100", StartDate = 3, StartPrice = 3 }
    var resu = AuctionItems.GroupBy(a => new { a.Category, a.Description }).Select(sg => new { ID = sg.Key.Category, Total = sg.Sum(oc => oc.StartPrice + oc.StartDate), Name = sg.Key.Description });
     You also can change your code to
    • SumTotal = sg.Sum(x => x.month_01+x.month_02+ ......)
    Have a nice day !
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Can't update master table when creating a materialized view log.

    Hi all,
    I am facing a very strange issue when trying to update a table on which I have created a materialized view log (to enable downstream fast refresh of MV's). The database I am working on is 10.2.0.4. Here is my issue:
    1. I can successfully update (via merge) a dimension table, call it TABLEA, with 100k updates. However when I create a materialized view log on TABLEA the merge statement hangs (I killed the query after leaving it to run for 8 hrs!). TABLEA has 11m records and has a number of indexes (bitmaps and btree) and constraints on it.
    2. I then create a copy of TABLEA, call it TABLEB and re-created all the indexes and constraints that exist on TABLEA. I created a materialzied view log on TABLEB and ran the same update....the merge completed in under 5min!
    The only difference between TABLEA and TABLEB is that the dimension TABLEA is referenced by a number of FACT tables (by FKs on the FACTS) however this surely should not cause a problem. I don't understand why the merge on TABLEA is not completing...even though it works fine on its copy TABLEB? I have tried rebuilding the indexes on TABLEA but this did not work.
    Any help or ideas on this would be most appreciated.
    Kind Regards
    Mitesh
    email: [email protected]

    Thats what I thought, the MVL will only read data that has changed since it was created and wont have the option to load in all the data as though it was made before the table was created.
    From what I have read, the MVL is quicker than a Trigger and I have some free code that prooved to work from a MVL using it as a reference to know what records to update. There is not that much to a MVL, a record ID and type of update, New, Update or Delete.
    I think what I will have to do is work on a the same principle for the MVL but use a Trigger as this way we can do a full reload if required at any point.
    Many thanks for your help.

  • When i try update firefox i am told - incompatible add on found- and assoon as they are made compatible firefox will update & re enable these add ons what do ihave to do to install this latest update?-ia getting concerned about security

    the info supplied civers current situation - info appears in window when asked to install update

    the info supplied civers current situation - info appears in window when asked to install update

  • Update Multiple Column with Single Command with Join between Two tables.

    This is our command where we are trying to update a table's two columns by pulling values from another table after joining. This query takes too much time to execute. Any suggestions ?
    UPDATE raw_alc_rmfscombinednew
    SET (BSC, CELL_NAME) =
    SELECT distinct raw_alc_R110combinednew.BSC, raw_alc_R110combinednew.CELL_NAME
    FROM raw_alc_R110Combinednew
    WHERE
    raw_alc_R110Combinednew.OMC_ID = raw_alc_rmfscombinednew.OMC_ID
    AND raw_alc_R110Combinednew.CELL_CI = raw_alc_rmfscombinednew.CI
    AND RAW_ALC_R110COMBINEDNEW.START_TIME = RAW_ALC_RMFSCOMBINEDNEW.START_TIME
    Results of Last execution:
    Elapsed Time (sec) 4,476.56
    CPU Time (sec) 4,471.88
    Wait Time (sec) 4.68
    Executions that Fetched all Rows (%) 100.00
    Average Persistent Mem (KB) 32.43
    Average Runtime Mem (KB) 31.59
    --------------------------------------------------------------

    Your update requires a full execution of the subquery for each row in the destination table (raw_alc_rmfscombinednew). Try rewriting as a MERGE. Tons faster.
    MERGE INTO raw_alc_rmfscombinednew  D
          USING ( SELECT distinct
                         BSC,
                         CELL_NAME
                         START_TIME
                    FROM raw_alc_R110Combinednew )  S
             ON (    S.OMC_ID     = D.OMC_ID
                 AND S.CELL_CI    = D.CI
                 AND S.START_TIME = D.START_TIME )
        WHEN MATCHED THEN
          UPDATE
             SET D.BSC        = S.BSC,
                 D.CELL_NAME  = S.CELL_NAME

  • Updating multiple columns

    I have an UPDATE statement with some complex CASE statements in the inner SELECT query which makes it impossible to set values like column_name1 = value1, column_name2=value2 . So i am getting ORA-00927: missing equal sign error.
    The UPDATE looks like
    SQL> UPDATE EMPCLONE
      2  SET EMPNO,ENAME,JOB=(SELECT EMPNO,ENAME,JOB FROM EMP);
    SET EMPNO,ENAME,JOB=(SELECT EMPNO,ENAME,JOB FROM EMP)
    ERROR at line 2:
    ORA-00927: missing equal signAny workarounds?

    >
    The UPDATE looks like
    SQL> UPDATE EMPCLONE
    2  SET EMPNO,ENAME,JOB=(SELECT EMPNO,ENAME,JOB FROM
    EMP);
    ET EMPNO,ENAME,JOB=(SELECT EMPNO,ENAME,JOB FROM EMP)
    line 2:
    ORA-00927: missing equal signAny workarounds?Enclose the column list after SET in brackets:
    test@ORA10G>
    test@ORA10G> drop table t;
    Table dropped.
    test@ORA10G>
    test@ORA10G> create table t (x number, y number, z date);
    Table created.
    test@ORA10G>
    test@ORA10G> insert into t (x,y,z) values (1,10,sysdate);
    1 row created.
    test@ORA10G> commit;
    Commit complete.
    test@ORA10G> select * from t;
             X          Y Z
             1         10 14-MAR-08
    test@ORA10G>
    test@ORA10G> update t set x,y,z = (select 2,20,sysdate from dual);
    update t set x,y,z = (select 2,20,sysdate from dual)
    ERROR at line 1:
    ORA-00927: missing equal sign
    test@ORA10G> update t set (x,y,z) = (select 2,20,sysdate from dual);
    1 row updated.
    test@ORA10G> commit;
    Commit complete.
    test@ORA10G> select * from t;
             X          Y Z
             2         20 14-MAR-08
    test@ORA10G>pratz

  • Need to update multiple columns using another table

    I have 2 tables. and i need to update rows of 1 table using another table
    Table1
    Serial_no.     payment_date     Payment_amt
    101     22/11/2010     150
    101     18/03/2011      355
    102     15/04/2011      488
    103     20/05/2011      178
    102     14/06/2011      269
    101     28/06/2011      505
    Table2
    Serial_no     Charge_amt      Last_paymt_dt     Last_paymt_amt
    101     255
    102     648
    103     475
    I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
    Update Table2
    set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
    where table1.Serial_no = table2.Serial_no group by payment_amt)
    kindly suggest how should i update.

    SQL> select * from table1
      2  /
    SERIAL_NO PAYMENT_DA PAYMENT_AMT
           101 22/11/2010         150
           101 18/03/2011         355
           102 15/04/2011         488
           103 20/05/2011         178
           102 14/06/2011         269
           101 28/06/2011         505
    6 rows selected.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255
           102        648
           103        475
    SQL> update  table2
      2     set  (last_paymt_dt,last_paymt_amt) = (
      3                                            select  max(payment_date),
      4                                                    max(payment_amt) keep(dense_rank last order by payment_date)
      5                                              from  table1
      6                                              where table1.serial_no = table2.serial_no
      7                                           )
      8  /
    3 rows updated.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255 28/06/2011            505
           102        648 14/06/2011            269
           103        475 20/05/2011            178
    SQL> SY.

  • Update of multiple columns

    Hi,
    how do I update some columns of a table within one statement?
    For Example,
    My tabel has column: a,b,c,d and I want wo update column a,c,d
    Thanks hor help,
    Walter
    Edited by: user457173 on Sep 22, 2008 11:26 AM
    Edited by: user457173 on Sep 22, 2008 11:26 AM
    Edited by: user457173 on Sep 22, 2008 11:27 AM

    Nicloei W wrote:
    2nd option doesnt seems to be convincing, can give you ora query fetch more rows...I was only giving the principles on the assumption that people generally know about adding where clauses to restrict their data. It wasn't a conclusive working example, just a sample example of how to update multiple columns with a single select statement (what that select statement is, is not important).
    Some people are just pedants. ;)

  • CMP update multiple rows

    Hi,
    Is there a way to update multiple rows when using CMPs.
    For example I can update multiple rows by this method.
    while (condition)
    cmp = cmpHome.findByPrimaryKey(key);
    cmp.setValue(newValue);
    Rather than this method is there a way that I can update many rows just as normal sql update.
    thanks in advance,
    chamal.

    If you want to concatenate Acol column with sysdate for 605 and 608 ....i think you need to code less (of what you have posted)
    UPDATE TEST
    SET TEST.ACOL =  TEST.ACOL || ' ' ||sysdate
    where
    test.acol in (605,608);--I don't know why you want this , Just given the suggestion as per the requirement.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Updating Multiple entities Programmatically in LightSwitch Html Client 2013

    hi,
    How to Update Multiple entities When Updating One entity in Server Side ?
    Thanks in Advance...

    You'll probably need to give a little more information about your particular scenario but if you're doing this update server side using the updating method of your entity then you have access to do what you like with any record/entity.
    If the entities are related then it may just be a case of a statement like:
    YourEntity.YourRelatedEntity.SomeProperty = "Hello world.";
    Or you could call a entity specifically from another table and update it accordingly:
    AnotherTable ent = DataWorkspace.ApplicationData.AnotherTable.Where(r => r.id == 5).FirstOrDefault();
    if (ent != null)
    ent.Description = "Hello World.";
    Hope that helps you.
    Paul.

Maybe you are looking for