Update..Union All   Vs  multiple individual Updates -- performance?

Hi All,
I have a procedure which fetches data from a remote database. It performs multiple updates on a single table. Will it be any better in terms of performance if I have all the updates combined into one update using a UNION ALL.
Please advice in terms of performance or any other options of improving performance..
INSERT INTO BALAN (
deal_id, projection_period, deposit, spread
SELECT DEALID, 1, nvl(to_char(sum(avg_deposit) / count(avg_deposit), '99999999999.99'), 0) deposit,
nvl(to_char(sum(avg_float)/ count(avg_float), '99999999999.99'), 0) spread
FROM BILLING.CAP_ANST1@LINK_BILLN01D a
WHERE account = AACCOUNT
AND group_ind = GROUPID
AND stamp = v_stamp_date
UNION ALL
SELECT DEALID, 3, nvl(to_char(sum(avg_deposit) / count(avg_deposit), '99999999999.99'), 0) deposit,
nvl(to_char(sum(avg_float)/ count(avg_float), '99999999999.99'), 0) spread
FROM BILLING.CAP_ANST1@LINK_BILLN01D
WHERE account = AACCOUNT
AND group_ind = GROUPID
AND stamp >= v_stamp_date_minus_2
UNION ALL
SELECT DEALID, 6, nvl(to_char(sum(avg_deposit) / count(avg_deposit), '99999999999.99'), 0) deposit,
nvl(to_char(sum(avg_float)/ count(avg_float), '99999999999.99'), 0) spread
FROM BILLING.CAP_ANST1@LINK_BILLN01D
WHERE account = AACCOUNT
AND group_ind = GROUPID
AND stamp >= v_stamp_date_minus_5
UNION ALL
SELECT DEALID, 12, nvl(to_char(sum(avg_deposit) / count(avg_deposit), '99999999999.99'), 0) deposit,
nvl(TO_CHAR(SUM(avg_float)/ COUNT(avg_float), '99999999999.99'), 0) spread
FROM billing.CAP_ANST1@LINK_BILLN01D a
WHERE account = AACCOUNT
AND group_ind = GROUPID
AND stamp >= v_stamp_date_minus_11;
---------------- OR---------------------------------
INSERT INTO IDM.balan
(DEAL_id, PROJECTION_PERIOD, deposit, spread)
SELECT DEALID, 1, nvl(SUM (avg_deposit) / COUNT (avg_deposit), 0) deposit,
nvl(SUM (avg_float) / COUNT (avg_float),0) spread
FROM BILLING.CAP_ANST1@LINK_BILLN01D a
WHERE aaccount = a.ACCOUNT
AND a.group_ind = groupid
AND stamp = (SELECT to_date(value, 'MM/DD/YYYY')
FROM APP_ENV
WHERE name = 'CUR_STAMP');
INSERT INTO IDM.balan
(DEAL_id, projection_period, deposit, spread)
SELECT DEALID, 3, nvl( TO_CHAR(SUM (avg_deposit) / COUNT (avg_deposit), '99999999999.99'),0) deposit,
nvl( TO_CHAR(SUM (avg_float)/ COUNT (avg_float), '99999999999.99'),0) spread
FROM BILLING.CAP_ANST1@LINK_BILLN01D a
WHERE aaccount = a.ACCOUNT
AND a.group_ind = groupid
AND stamp >= (SELECT ADD_MONTHS (to_date(value, 'MM/DD/YYYY'), -2)
FROM APP_ENV
WHERE name = 'CUR_STAMP');
INSERT INTO IDM.balan
(DEAL_ID, projection_period, deposit, spread)
SELECT DEALID, 6,
nvl( TO_CHAR(SUM (avg_deposit) / COUNT (avg_deposit), '99999999999.99'),0) deposit,
nvl( TO_CHAR(SUM (avg_float)/ COUNT (avg_float), '99999999999.99'),0) spread
FROM billing.CAP_ANST1@LINK_BILLN01D a
WHERE a.ACCOUNT = aaccount
AND a.group_ind = groupid
AND stamp >= (SELECT ADD_MONTHS (to_date(value, 'MM/DD/YYYY'), -5)
FROM APP_ENV
WHERE name = 'CUR_STAMP');
INSERT INTO IDM.balan
(DEAL_ID, projection_period, deposit, spread)
SELECT DEALID, 12, nvl( TO_CHAR(SUM (avg_deposit) / COUNT (avg_deposit), '99999999999.99'),0) deposit,
nvl( TO_CHAR(SUM (avg_float)/ COUNT (avg_float), '99999999999.99'),0) spread
FROM billing.CAP_ANST1@LINK_BILLN01D a
WHERE aaccount = a.ACCOUNT
AND a.group_ind = groupid
AND stamp >= (SELECT ADD_MONTHS (to_date(value, 'MM/DD/YYYY'), -11)
FROM APP_ENV
WHERE name = 'CUR_STAMP');
Thanks in advance!
Appreciate your help!
Thanks
Bob

Hi Bob,
Maybe I misunderstood, but couldn't you just:
insert into balan(deal_id
                 ,projection_period
                 ,deposit
                 ,spread)
   select dealid
         ,case
             when stamp  = v_stamp_date          then 1
             when stamp >= v_stamp_date_minus_2  then 3
             when stamp >= v_stamp_date_minus_5  then 6
             when stamp >= v_stamp_date_minus_11 then 12
          end
             projection_period
         ,nvl(to_char(sum(avg_deposit) / count(avg_deposit), '99999999999.99')
             ,0)
             deposit
         ,nvl(to_char(sum(avg_float) / count(avg_float), '99999999999.99'), 0)
             spread
     from billing.cap_anst1@link_billn01d a
    where account = aaccount
      and group_ind = groupid
      and stamp between v_stamp_date_minus_11 and v_stamp;Regards
Peter

Similar Messages

  • I can not update my installed apps from the App Store Update page.  I can individually update from the App Store Purchased page.  I tried a soft reset but still unable.  Any suggestions?

    I can not update my installed apps from the App Store Update page.  I can individually update from the App Store Purchased page.  I tried a soft reset but still unable.  Any suggestions?

    You are doing all that you cn do right now other than to update the apps in iTunes on your computer and sync them to the iPad.
    There has been a problem with the App Store updates tab for a few days now and we are all waiting for Apple to fix it.
    Look at all of the discussions on the iPad forum that are talking about this right now.

  • UNION ALL affect on recordset updateability

    Hi
    We have a legacy database that was hosted in SQL Server 2000 which is now hosted in SQL Server 2008 R2 in SQL 2000 compatibility mode.
    A legacy application accesses a table in the database via a stored procedure and creates a disconnected recordset. The SQL that is executed by the stored procedure is like this (much simplified) :
    select Id, colA, colB from MYTABLE where Id IN (1,2)
    UNION ALL
    select Id, colA, colB from MYTABLE where Id BETWEEN @a and @b
    When the database was hosted in SQL Server 2000 the recordset was updateable e.g. colA could be assigned a new value but when hosted in SQL Server 2008 R2 it is not; the program gets error 'Multiple step operation generated errors...'. These changes to the
    disconnected recordset are temporary and used to compare against another recordset at a later time to perform the appropriate insert/update/delete action.
    I've tried both SQLOLEDB.1 and SQLNCLI10 data providers.
    Is there a way I can continue to get the SQL 2000 behaviour so that I'm not forced to change the code (SQL and/or program) immediately?
    Thanks
    Craig

    Hello CNicho,
    Since this issue is related SQL Server and after confirming with SQL Server experts, I suggest that you could post it to:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=transactsql
    This current forum you post to is used to discuss Data platform development using ADO.NET managed providers, especially System.Data.SqlClient, System.Data.Odbc and System.Data.Oledb.
    Regards.
    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.

  • Cannont update because all playlists selected to update no longer exists.

    When I connected to itunes today, itunes states that the songs on my ipod cannot be updated because all the playlists no longer exist. I opened up MY playlist under just my name and there is nothing there. My library is still there and all the playlists I created are still there. Mine, the one that appears when the ipod connects, is empty. So I went to edit and selected a few playlists and then itunes stated that the dick couldn't be written to or read from. I also tried different ways to get that library in my list. I don't get it! I went to apple support and discussions, and the only thing I haven't done so far is to RESTORE my ipod. It I do this won't I lose my library on itunes and all the work I'be put into it??? PLEASE HELP. This should be more user friendly!
    dell   Windows XP Pro  

    This may resolve your problem.
    http://discussions.apple.com/thread.jspa?messageID=607312&#607312

  • Yosemite updates are all necessary on individual iMacs?

    I used to be able to ignore App updates under Mountain Lion.  The new system doesn't seem to allow that now.  I don't want to have them listed every time I go online to the App Store.  Some like RAW files, for example,  do not apply to me, because I don't have that particular camera.
    Am I missing something?

    I Never thought to do this. I haven't tried it but it sounds logical.  There used to be, if I remember correctly, a drop down menu to hide it in future.  Then to reverse it later if it was required.  I will try it, usually the simple way is right.  I have this obsession with not having anything on my iMac that I don't need and I found downloaded some of thsee type of files because I didnt want to mess my computer up.
    thanks for your help.  I shall try it when the need arises.

  • Update trigger syntax for multiple collumn update

    Hi
    I would like to create an update trigger that updates 3 collumns in another table.
    This works for one collumn:
    CREATE OR REPLACE TRIGGER DBNAME.Update_EVENT
    BEFORE UPDATE
    ON DBNAME.DB_EVENTS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    BEGIN
    UPDATE DB_EVENT_LOG ELOG
    SET
    COMPLETION_EVENT = :NEW.COMPLETION_EVENT
         WHERE :OLD.RECORD_ID = ELOG.RECORD_ID ;
    EXCEPTION
    WHEN OTHERS THEN
    -- log the error and re-raise
    RAISE;
    END ;
    but this does not work for multiple collumns:
    CREATE OR REPLACE TRIGGER DBNAME.Update_EVENT
    BEFORE UPDATE
    ON DBNAME.DB_EVENTS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    BEGIN
    UPDATE DB_EVENT_LOG ELOG
    SET
    (COMPLETION_EVENT
    , COMPLETION_DT_TM
    , COMPLETED_BY)
    =
    (:NEW.COMPLETION_EVENT
    , :NEW.COMPLETION_DT_TM
    , :NEW.COMPLETED_BY)
         WHERE :OLD.RECORD_ID = ELOG.RECORD_ID ;
    EXCEPTION
    WHEN OTHERS THEN
    -- log the error and re-raise
    RAISE;
    END ;
    What am i doing wrong?

    Try selecting from DUAL:
    SQL> CREATE TABLE emp_test AS SELECT * FROM emp
    Table created.
    SQL> CREATE OR REPLACE TRIGGER emp_trg
       AFTER UPDATE
       ON emp
       FOR EACH ROW
    BEGIN
       UPDATE emp_test
          SET (sal, comm) = (SELECT :NEW.sal,
                                    :NEW.comm
                               FROM DUAL)
        WHERE empno = :NEW.empno;
    END;
    Trigger created.
    SQL> UPDATE emp
       SET sal = 5000,
           comm = 5000
    WHERE empno = 7369
    1 row updated.
    SQL> SELECT empno,
           sal,
           comm
      FROM emp_test
    WHERE empno = 7369
         EMPNO        SAL       COMM
          7369       5000       5000

  • Photshop CS6 fails to update while all other CC apps update properly

    PS CS6 repeatedly fails to update with the error code U44M1P7. What can I do to fix this?

    PS CS6 repeatedly fails to update with the error code U44M1P7. What can I do to fix this?

  • HT4623 my ipod does not say software update at all how do i update my ipod touch

    my ipod needs to be updated and i cant becuz it doesnt say software update on it anywhere...
    need help asap

    To update
    The Settings>General>Software Update comes with iOS 5 and later.
    Connect the iPod to your computer and update via iTunes as far as your iPod model allows
    iOS: How to update your iPhone, iPad, or iPod touch
    A 1G iPod can go to iOS 2.2 via iTunes and iOS 3.1.3 via
    Purchasing iOS 3.1 Software Update for iPod touch (1st generation)       
    https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/touchLegacyLandingPage
    A 2G to 4.2.1. Requires iTunes version 10.X. If a Mac it requires OSX 10.5.8 or later. With OSX 10.4.11 you can only go to iTunes 9.X which gets you as high as iOS 4.1
    A 3G to 5.1.1  Requires iTunes version 10.5 or later
    A 4G to 6  Requires iTunes version 10.7 or later. For a Mac, that requires a Mac with OSX 10.6.8 or later
    Identifying iPod models
    Only the 5G iPod can go to iOS 7

  • What's the best way to insert/update thousands records in multiple tables

    Can anyone give an example of how to insert/update thousands records in multiple tables on performance wise? or what should I do to improve the performance?
    Thanks
    jim

    You can see a set of sample applications in various scenarious available at
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/content.html

  • "songs..can't be updated b/c all the playlists for updating no longer exist

    My Ipod was "off power" for so long that it "forgot" all its music. Now when I plug it in to my base computer, rather then synching it says "songs on the ipod "name" cannot be updated because all the playlists for updating no longer exist"

    Hey.
    See if this can help;
    http://discussions.apple.com/thread.jspa?threadID=121728&tstart=150
    Cheers!
    -Bryan

  • Elements 12 will not run until it is "updated". All update attempts fail. Apparently, no tech support actually exists for this product.

    Photoshop Elements 12 recently installed. It requires an update. All attempts (10+) to update the software have failed; It downloads for an hour or so, but will not install. Adobe should work for the CIA; your success at hiding live employees from the public is outstanding.

    reset your preferences by holding down shift-ctrl-alt (win) or shift-cmd-alt (mac) while starting pse 12.  if done correctly you'll see a confirmation dialog.

  • How can I print to my HP OfficeJet 6500 Wireless Printer from my iPhone 4S which used to work before AirPrint printers were even available? (running Mac Lion OS, all software and HP sw updates are all performed)

    How can I print to my HP OfficeJet 6500 Wireless Printer from my iPhone 4S which used to work (on prior iPhones) before AirPrint printers were even available? (running Mac Lion OS, all software and HP sw updates are all performed)
    I don't get it, I read one post about why would we have to buy an AirPrint Printer when we have used the "print to a wifi printer" just fine in the past?  Yes I feel that's exactly what's happening to me now too. I want to print from my iPhone and iPad to my WiFi Printer which is also now connected to my Airport Express WiFi network just fine. No problems.

    Very glad you added that bit of information because I see different problems similar to this.  I want to share with them what you did and hopefully you not only fixed your specific problem but you can lend some more advice to others with problems like this. Thanks!
    Don't forgot to say thanks by giving "Kudos" if I helped solve your problem.
    When a solution is found please mark the post that solves your issue.
    Every problem has a solution!

  • Updatable Materialized View with Union ALL

    (please don't ask about db structure)
    DB: 11gR2
    create table table_1  (
        id number primary key,
        val varchar2(100)
    create table table_2  (
        id number primary key,
        val varchar2(100)
    insert into table_1(id) values (0);
    insert into table_1(id) values (2);
    insert into table_1(id) values (3);
    insert into table_1(id) values (4);
    insert into table_1(id) values (5);
    insert into table_2(id) values (10);
    insert into table_2(id) values (12);
    insert into table_2(id) values (13);
    insert into table_2(id) values (14);
    insert into table_2(id) values (15);
    update table_1 set val='Table1 val:'||id;
    update table_2 set val='Table2 val:'||id;
    create view v_table_all as
    select * from table_1
    view V_TABLE_ALL created.
    select * from v_table_all;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             YES       YES        YES      
    VAL                            YES       YES        YES      
    update v_table_all set val='XXX changed' where id = 3;
    1 row updated.
    select * from table_1;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      XXX changed                                                                                         
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    rollback;
    select * from table_1;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    create or replace view v_table_all as
    select * from table_1
    union select * from table_2;
    view V_TABLE_ALL created.
    select * from v_table_all;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    10                     Table2 val:10                                                                                       
    12                     Table2 val:12                                                                                       
    13                     Table2 val:13                                                                                       
    14                     Table2 val:14                                                                                       
    15                     Table2 val:15  
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             NO        NO         NO       
    VAL                            NO        NO         NO       
    trying update:
    update v_table_all set val='XXX changed' where id = 3;
    SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
    01732. 00000 -  "data manipulation operation not legal on this view"
    *Cause:   
    *Action:
    drop view v_table_all;
    view V_TABLE_ALL dropped.all is ok before this point.
    now we want create a new materialized view with some query
    create  materialized view v_table_all
    as
    select * from table_1
    union all select * from table_2 ;
    materialized view V_TABLE_ALL created.
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             YES       YES        YES      
    VAL                            YES       YES        YES       it seems to be ok with update.
    but...
    update v_table_all set val='XXX changed' where id = 3;
    SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
    01732. 00000 -  "data manipulation operation not legal on this view"
    *Cause:   
    *Action:How can solve this issue??
    Any suggestion

    Looks like user_updatable_columns sort of thinks the MV is just a table - I don't know about that...
    An MV on a single table can be updated - I tried that and it works:
    create materialized view mv_table_1 for update
    as
    select * from table_1;I noticed [url http://download.oracle.com/docs/cd/E11882_01/server.112/e16579/advmv.htm#sthref294]examples stating the UNION ALL needs a "marker" so Oracle can know from the data which source table a row in the MV originates from - like this:
    create materialized view v_table_all for update
    as
    select 'T1' tab_id, table_1.* from table_1
    union all
    select 'T2' tab_id, table_2.* from table_2 ;But that also fails (the "marker" requirement was specifically for FAST REFRESH, so it was just a long shot ;-) )
    What are you planning to do?
    <li>Create the MV.
    <li>Update records in the MV - which then is no longer consistent with the source data.
    <li>Schedule a complete refresh once in a while - thereby overwriting/losing the updates in the MV.
    If that is the case, I suggest using a true table rather than an MV.
    <li>Create table t_table_all as select ... .
    <li>Update records in the table - which then is no longer consistent with the source data.
    <li>Schedule a job to delete table and insert into table select ... once in a while - thereby overwriting/losing the updates in the table.
    In other words a kind of "do it yourself MV".
    I cannot see another way at the moment? But perhaps try in the data warehousing forum - the people there may have greater experience with MV's ;-)

  • My iPad mini won't update my apps.  I have closed all open apps, done multiple resets but I show 24 updates and when I hit the update, the screen is blank.

    My iPad mini won't update my apps.  I have closed all open apps and done multiple resets.  I hit update and the screen is blank, even though the bubble shows 14 to update.

    If you are getting the blank app update screen, many people are having this problem over the last couple of days.
    According to Fly150 in another discussion, this will work.
    If you want to update the Apps while waiting for Apple to fix Updates:
    1. Go to App Store
    2. Select Purchased
    3. Select All
    4. Scroll down to find the Apps showing update
    5. Select update on the Apps
    This should update the Apps and get rid of the update count in App Store. Apple needs to fix this. It is a workaround only until then.

  • Multiple Rows Update / Refresh Toplink Query when database trigger involved

    Hi everybody!
    I have two easy troubles for you; the platform is the same as the SRDemo Toplink version.
    1.     Multiple Rows Update: I want to update with mergeEntity method, multiple rows for an isolated table; that method receives a parameter that I try to bind with the iterator "dataProvider" but it only merges the first row, not all, any other combination returns an error.
    What I want to do is to have a form (like tabular forms in Apex) that lets me update multiple rows in a single page. ¿May anyone tell me how to do it?
    2.     Refresh Toplink Named Query: I have a list on a page with two columns. From another page, a button does an action that fires a database trigger that updates one of the columns on the list´s page. When I go back to the list, it is not updated; however, the CacheResults´s property is set to false on the iterator.
    Thanks in advance,
    Alejandro T

    I didn't use it (yet), but - you might take a look. You'll find a [url http://www.oracle.com/technetwork/developer-tools/apex/application-express/apex-plug-ins-182042.html]Timer plug-in on this page. It is a dynamic action which allows you to periodically fire other dynamic actions in the browser. For example use the timer to refresh a region every five minutes. You can perform any dynamic action you want using this infrastructure.So I was thinking: you might use it to run a dynamic action which would check whether something changed in that table (I suppose you'll know the way) (for example, a database trigger might set a flag in some table, timestamp or similar), and - if you find that something really changed - refresh the page.
    As I said, I never used it so that's pure theory. Someone else might know better, though.

Maybe you are looking for

  • Songs I purchased on my iPhone not showing up in my itunes library, or purchase history. The iPhone was unauthorized, but connected to my iTunes account.

    So I got a new iPhone about a month or two ago (I no longer have this iphone) and I bought some albums from iTunes but now that I'm on my computer (which the iphone is not authorized on) I cant seem to find out how to download the albums I downloaded

  • 5800 screen problem....

    hey frnds i had fitted magnet to stop lines on screen of 5800 ,but some times when i unlock the screen the screen shows black and white light is flashing and it take 2-3 min to recover plz help what to do..?

  • Problem in screen painter in ECC6.0

    hi experts. i'm installed ecc6.0. In screen  paintter(se51)  when i click on layout button i'm getting texteditor i'm not getting screen elements. how can i solve this problem. tell me te alternate solution.

  • Webdynpro application in mobile

    Hi friends ,     i have developed a webdynpro application.when i called the url in my system application is opening,but when i call the same url its getting dump im my mobile showing rabax_state .can we directly call the urls in our mobiles .is there

  • Why go to iDVD 9

    I am currently running iDVD 8 and, except for the fact that it occasionally fuddles up my 4:3 projects and makes them 16:9, it seems to work well. So, why upgrade to iDVD 9? Are there any performance enhancements? Does it still have the 4:3/16:9 misf