doubt about the update

Hi all

Three statements to update, I need to run on a single table.
Is there a way I can update instructions executed all three in a single statement?
    UPDATE xxops_forecast_extract b SET territory_id = (SELECT a.territory_id
         FROM fdev_hier_node_mv a
         WHERE a.shr_node_id = b.shr_node_id
          AND NVL(end_dt,SYSDATE) > SYSDATE) ;
    COMMIT;

    UPDATE xxops_forecast_extract b SET position_id = (SELECT a.row_id
        FROM s_postn a
        WHERE a.name = 'TD-'||UPPER(b.am_id))
        WHERE position_level = 7
        AND b.am_id IS NOT NULL;
    COMMIT;
  
    UPDATE xxops_forecast_extract b SET position_id = (SELECT a.row_id
        FROM s_postn a
        WHERE UPPER(a.desc_text) = UPPER(TRIM(B.POSITION_NAME)))
        WHERE position_level = 7
        AND b.am_id IS NULL;
 Below are the sample data for the tables. 

 xxops_forecast_extract 
 shr_node_id am_id position_name  position_id  territory_id
 2231211     Dave     (null)        (null)       (null)
 2231211     Michele  (null)        (null)       (null)
 2231211     (null)   COMM WEST 230 (null)       (null)
 2231211     (null)   COMM ISAM 110 (null)       (null)

 fdev_hier_node_mv
 shr_node_id territory_id 
  2231211      5694


 s_postn
 row_id    name       desc_text
 12122   TD-Dave     (null)
 12123   TD-Michele  (null)
 89381   (null)          COMM WEST 230
 89382   (null)          COMM ISAM 110

 Resulting table after update

 xxops_forecast_extract 
 shr_node_id am_id position_name  position_id  territory_id
 2231211     Dave     (null)        12122       5694
 2231211     Michele  (null)        12123       5694
 2231211     (null)   COMM WEST 230 89381       5694
 2231211     (null)   COMM ISAM 110 89382       5694
Thank you all.

Hello

You can combine the statements by combining subqueries.
No logic not apply to all the the original updates must be out of the WHERE clause and put in a CASE statement.
The CASE statements should "update" column to itself if none of the conditions apply.

For example, your final two statements UPDATE, that have subqueries on s_postn, both can be combined like this:

UPDATE     xxops_forecast_extract     b
SET     position_id =
     (
     SELECT     CASE
               WHEN     (     b.am_id          IS NOT NULL
                    AND     UPPER (a.name)     = 'TD-' || UPPER (b.am_id)
                    )
               OR     (     b.am_id          IS NULL
                    AND     UPPER (a.desc_text)     = UPPER (TRIM (b.position_name))
                    )
               THEN     a.row_id
               ELSE     b.position_id
          END
     FROM     s_postn     a
        WHERE     UPPER (a.name)          = 'TD-' || UPPER (b.am_id)
     OR     UPPER (a.desc_text)     = UPPER (TRIM (b.position_name))
     )
;

There seems to be some mistakes in the statemnts UPDATE that you posted. For example, the last two refer to a column called position_level that does not exist in the other table.
The above statement produces the results you want with the data you've posted.

As you can see, the code is much harder to understand, debug and maintain.
If the performance gain (if any) justifies the addional complexity is debatable in this case.
I'm sure that combining all three queries would be useful.

Consider using the MERGE: it is sometimes easier to use, even if, as in this case, you're never insert.

Tags: Database

Similar Questions

  • Doubt about the update/insertion of a Table

    I have a long SQL insertion. While SQL is running, update one or more tables sources. What data will be inserted by the SQL in the target table, updated or before update?

    Hello

    I said regarding how widespread, this market not in what concerns the selection.

    -Pavan Kumar N

  • HP Pavilion dv4-1120br: doubts about the BIOS update for my model with the operating system current instaled.

    Hello

    I have a HP Pavilion dv4-1120br, I know that this model of HP laptop is old, but I instaled the 64 bit of Windows 10 on my machine and saw that my BIOS is version F.30 and the last of them available on the site of HP F.66 has.

    The problem is that this model is not suport for Windows 10 because, as I said, is too old. Can I download and run the update of the BIOS for Windows 7 64-bit available in the Web site, or I need to downgrade my OS to Windows 7, update the BIOS and then pass it back to Windows 10?

    Thanks for the help!

    Cantarino

    Hello;

    Let me welcome you on the HP forums!

    Your second proposal is correct - as the updates to the BIOS on the HP site are specific to the OS version and if you try to run one for Win7 in Win10, it will refuse to run.

    Good luck

  • Firefox I want to find out about the updates only when the ons add that I installed currently become compatible. Is this possible?

    Firefox keeps advising me up-to-date even if a few Add ons are not compatible with the newer version. Although I don't want to be notified when an update is available, I won't update if the add ons are not compatible. Also, advising me update is useless because I will not refresh firefox when all add ons are not compatible.

    Is it possible to put the automatic notification about the availability of updates to appear only when all add ons are compatible?

    You can install this extension to see the information of current compatibility on the subject: addons page.

  • General question about the updates and version number

    I have a general question about versions and update.  I'm new on this and am in the deep end of learning I want.

    In vSphere web client, I see the following versions (these are exactly as the seller, he left a few months that I have screenshots in my documentation that match)

    Version - VMware ESXi, 5.1.0 1612806

    Profile - Dell (updated) ESXi - 5.1 - 799733 (A00)

    I am trying to familiarize themselves with the Update Manager and I noticed that there are a lot of patches and updates available.

    Lists of Update Manager 5 patches as "Missing" with Red x but directly above them are a list of patches with green tick indicating that "installed" - it is perhaps obvious, but im guessing 'installed' means really installed when displayed on the screen - there is an update installed, labeled "ESXI 5.1 all the update 2-' would be able to tell that it has been installed by the details of profile/version above?

    I don't think it's a big deal at this stage, but if I install all missing patches and then the details of the version/profile change in summary screen?

    I hope this makes sense.

    Thank you

    This article allows to correlate the updated version: products VMware correlating build numbers to update levels (1014508)

  • I have a doubt about the file .folio and publications

    Hello, I m new here.

    I want to start working with DPS, but I have a doubt about which version to buy.

    At the moment I have one customer just wants to publish a magazine, but my intention is to have more customers and publish more magazines.

    If I buy the unique edition of DPS, I read that I can publish a single file .folio. What it means? Each folio file represents a publication?

    Please, I need help to understand this before you purchase the software.

    Thank you very much

    Paul

    Here's a quick blog I wrote to compare the simple edition and

    multifolio apps:

    http://boblevine.us/Digital-Publishing-Suite-101-single-Edition-vs-multi-Folio-apps/

    Bob

  • Questions about the update of an application in the app store

    I am a member of creative cloud working with simple editing DPS. My app was approved by Apple and is in the store. But, of course, there is a typing error. What should I know about the submission of an updated version. Should have a new 1.1 version number to say? Can I use the same mobile both provision and development 12 certificates? Is the review ordering process more when it's an update?

    Thank you

    Chuck

    Hi Chuck,

    Subscribe to Adobe Creative cloud can revise their applications (and submit their applications reconstructed at Apple) as long as they subscribe to creative cloud. When you change your application, use the same ID App and distribution provisioning profile to create the new custom Viewer. In DPS App Builder, select the existing application that you have created and click on modify. Specify the latest version of the app, if you want and follow the prompts to create a new app download and test the development agenda. In iTunes Connect, click on manage your Applications, click the application that you want to update, and then click Add Version. Follow the prompts and then use Application Loader to download the .zip file.

    Concerning

    PEREADEL

  • Question about the update

    So when I bought my phone it was already updated to Lollipop (5.1) and missing only the updated jour.264. When I updated the phone I got only 47% battery (some say I shoukd have more than 80%) and the plant does not reset it.

    Bad conduct? Thank you!

    Nothing, keep an eye on the features of the software. And enjoy your device.

  • Question about the update of the ICS

    Hello

    I've updated my bow to android 4.0.4 yesterday, and his great performance, I just want to ask when I updated it I did not remove my SIM and SD card, after updating all my contacts where always there and my installed is still installed, is this ok? I want to say that I expected that my installed applications will be

    deleted and my contacts, my messages and call logs too but, after the update, nothing has been deleted and the phone works to 4.0.4 android os, pls help.

    P.S. the updated software was great, my phone is running smooth, thanks Sony,

    Yes, its normal, when the update using SUS you have two options here, update your phone without deleting your files or factory resetting your phone then install the update, or if you download the OTA update no file will be deleted. If you have problems you can reinstall the update or data factory reset your phone.

  • Yet another question about the update with the shutters tab

    I am quite new to this, but I've been scouring the boards and try many different things, and I decided to ask for advice.

    There are other threads similar to my problem such as:

    http://supportforums.BlackBerry.com/T5/Java-development/SetFocus-issue-with-tabbed-screen-page/m-p/6...

    http://supportforums.BlackBerry.com/T5/Java-development/how-to-delete-a-Manager-or-a-field-that-is-c...

    I have a set up tabbed pane based on the example and everything works fine until I have delete a line from a VerticalFieldManager. It is by default the focus on the first item on the screen, and I get this. My problem is trying to substitute or replacement behavior.

    My screen implements the FocusChangeListener for the buttons on the tab (custom LabelFields).

    I tried many different variations - I tried to manage the update completely manual and ended with a bit of a mess. I tried to capture the event navigationUnclick() and coding of the focusChanged() method to manually switch the update, but it seems that the focusChanged() method is called before the focusChanged(), which doesn't help me.

    As I said I am pretty new to this so I could do something very stupid, but I don't really understand the focus handling implementation. A kick in the right direction would be appreciated.

    Thank you.

    You can have a NullField in your managers before all other areas - in this way, even if you delete the rest, the NullField might keep the focus.

    If this does not help, try the substitution of sublayout for your managers, call super.sublayout and then explicitly setFocus to your NullField (the deletion of any field causes a display Manager to rearrange).

  • No response to questions about the updates on the CC or LR Help menu

    I recently spent my account for a free membership of canon 1 year after having bought a camera from them.  Now, I find that when I click on the drop-down list on CC emblem at the top of my screen, it is empty.  Also, when I try to see the updates from one of the two LR or CC applications, I get no answer.  What has gone wrong

    Hello

    I think you are referring to the white empty window of CC desktop application.

    Please refer to the threads below where this issue has been addressed:

    Creative cloud is empty window why?

    Cloud Desktop App is empty?

    New application Cloud Creative unusable: it is empty!

    Re: Empty opening creative cloud app

    Kind regards

    Sheena

  • Doubt about the Index

    Hi all

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production."
    AMT for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    I have a question about the index. Is - this required that the index will be useful if we have a "WHERE" clause I tried to find myself there but do not.
    In this example I haven't used where clause used but group. But it gives a comprehensive analysis. Is it possible to get the scan interval or something else using Group by?
    SELECT tag_id FROM taggen.tag_master GROUP by tag_id 
    
    Explain Plan:
    Plan hash value: 1688408656
     
    ---------------------------------------------------------------------------------------
    | Id  | Operation             | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |               |  4045 | 20225 |     6  (17)| 00:00:01 |
    |   1 |  HASH GROUP BY        |               |  4045 | 20225 |     6  (17)| 00:00:01 |
    |   2 |   INDEX FAST FULL SCAN| TAG_MASTER_PK |  4045 | 20225 |     5   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------

    Hello

    SamFisher wrote:
    Since I was on what they do full scan. Is it possible to restrict of fullscan without using where clause?
    I guess having limit clause but not quite know.

    Why?
    If this query is producing good results, then you need a full analysis.
    If fool you somehow the optimizer by doing a scan of interval, it will be slower.

  • Some doubts about the topology, interfaces and security modules

    Hello

    Below, some questions about the ODI:


    1. to use an LKM ODI always ask to use two different DATASERVERS (one for the SOURCE) and another to the TARGET?

    2. what would be the best way to create a new IKM with GROUP BY clauses?

    3. What is the required minimum PROFILE for developers users could import projects created in other ODI environments?

    4. If a particular WORK_REP is lost, it is possible that retrieve projects from version control information stored in the MASTER_REP?

    1.) Yes. LKM always loads data from one root to another.
    More than once I saw that even if there is a single physical server, several servers are configured in the topology Manager. This would lead to the use of a LKM because ODI consider 2 different servers.
    If the physical server is set only once, LKM won't be necessary.

    2.) IKM automatically adds a GROUP BY clause if it detects an aggregation function in the Interface implementation.

    3.) try to use the profile of the creator of NG.

    4.) this is not an easy task. But all the versioned objects are compressed and stored in a BLOB field in the master repository.
    You will need to know the names and versions you need to recover.
    SNP_VERSION and SNP_DATA have this information. Retrieves the field BLOB SNP_DATA and unpack using a zip utility. This will give you the XML property of the object that was transferred.
    Now, you can import this xml file and retrieve the object.

    You will need to loop through all the records in order of I_DATA, then extract to .xml file, and then import them to build the work rep.

  • Do I need to worry about the update of the firmware on Micron RealSSD C400?

    Hello. The SSD drive my EliteBook 8560p is a MTFDDAK128MAM-1J1, which is a series of C400 of Micron. I was recently informed of the bug in the firmware in the Micron C400/Crucial M4 devices with firmware Rev. 0009. the bug causes the reader to crash after it hits 5184 hours of operation time and the only way to correct or prevent this error is to upgrade to the reverend firmware 0309 Micron / Crucial, released in January 2012. However, this firmware is, according to Micron / Crucial, not apply to devices which is bought as original equipment in a computer system. MTFDDAK128MAM-1J1 in my computer said that its firmware was 0809, which I can't find any information on. So my question is: anyone knows it if the Apocalypse 0809 firmware is based on the official firmware 0009 and will therefore be affected by the mentioned previous bug? If so, when and where I'll be able to download a firmware updated for the reader in my EliteBook?

    Thanks for your help. I was also in touch with Micron about this, and I received a confirmation from them that shipped for HP SSD drives is NOT affected by this bug in the firmware.

  • Some doubts about the navigation in unifying

    Hi all

    I had a few questions about unifying navigation.

    Is it possible to move the admin mode user mode access level?

    I mean, if a particular feature as Manager of the shell I can only access from admin mode is it possible to provide access even in user mode?

    If so, how?

    My 2nd question of doubt is, currently, we can access company BPs level "Journal of society" or "Resource Manager" under shell 'Company Workspace'.

    Is it possible to move the "journal of the society" or "Resource Manager" in the folder? If yes how?

    I tried in "navigation user mode" to move the company BPs level at shell of the House, but I can't do it.

    To answer your questions:

    (1) User-Mode browser can have the user feature included. You cannot change the view mode Admin or move functions admin for user mode.

    (2) you cannot move these on the Home tab.

Maybe you are looking for