With the help of Merge for Update, Insert, Update and also to delete outdated records

Hi all!!!

Suppose that a credit memo the following table called Orders:
ORDERID        STATUS      PRICE 
---------- ---------- ---------- 
         1          0        100 
         2          0        200 
         3          0        300 
         4          0        350 
         5          0        390
In addition, there are a procedure that will generate data on a global temporary table, called Orders_Temp. This temporary table will be used to update the Orders table. + commands + have a trigger that will perform different operations when an Insert, Update, or Delete command is executed.

Consider the table of Orders_Temp to have the following data after you run a procedure that is responsible for the update of order data:
ORDERID        STATUS      PRICE 
---------- ---------- ---------- 
         1          1        100 
         2          2        200 
         3          0        300 
         5          0        390 
         6          0        350
As you can see, orders 1 and 2 have been updated. Order 3 and 5 were intact, order 4 has been deleted and command 6 inserted. Fusion will take care of properly manage orders 1, 2, 3, 5 and 6, although producing an update of order 3 and 5, which have not changed.

So, here are the questions:
(1) how could remove the 4 arrestedorder, as this order was not present on Orders_Temp? Is it possible to use the merge command to do this?
(2) is it possible to generates not a update operation for orders of 3 and 5, which have not changed?

I m using Oracle 10.2 SE.

Thank you very much!
Regis

Hello

Please try this. Not tested! with 9i. I think you can do this by using the union all.

MERGE INTO orders tgt
 USING (SELECT A.*, 1 mask
          FROM orders_temp A
        UNION ALL
        SELECT A.*, 0
          FROM orders A
         WHERE NOT EXISTS
                 (SELECT 1
                    FROM orders_temp b
                   WHERE A.order_id = b.order_id)) src
    ON (tgt.order_id = src.order_id)
WHEN MATCHED
THEN
  UPDATE SET tgt.status = src.status, tgt.price = src.price
     WHERE src.mask = 1
       AND tgt.status != src.status
       AND tgt.price != src.price
  DELETE
     WHERE src.mask = 0
WHEN NOT MATCHED
THEN
  INSERT VALUES (src.order_id, src.status, src.price)

or you could try to use a full outer join and treat NULL values.
G.

Edited by: g. March 8, 2011 11:17

changed to the Union all the

Tags: Database

Similar Questions

  • With the help of MERGE for update and insert a table

    -Oracle 11 g
    -Windows 2008

    I'm working on a script which requires update on insertion according to requirement.

    I table_a in the Test database and table_b in a Production environment and want to sync database availability.
    I need help to place the dblink (where to put it etc.).
    Here's what I've got so far:

    / * Update the tables for the production of Test environment
    November 28, 2011
    */

    FUSION
    in prod.tbl_link P
    using (select * from test.tbl_link) T
    On(prod.tbl_link.link_id = test.tbl_link.link_id.ID)
    When matched then
    Update
    Set P.LINK_ID = T.L_LINK_ID,
    P.L_URL = T.L_URL =,
    P.L_TITLE = T.L_TITLE,
    P.L_DESCRIPTION = T.L_DESCRIPTION,
    P.ISSUE_DATE = T.L_ISSUE_DATE,
    P.PUBLICATION_DATE = T.L_PUBLICATION_DATE,
    P.LAST_MODIFIED_DATE = T.L_LAST_MODIFIED_DATE,
    P.L_ICON_NEW = T.L_ICON_NEW,
    P.L_ICON_RECENT = T.L_ICON_RECENT,
    P.L_ICON_NEW_FROM_DATE = T.L_ICON_NEW_FROM_DATE,
    P.L_ICON_NEW_TO_DATE = T.L_ICON_NEW_TO_DATE,
    P.L_ICON_RECENT_FROM_DATE = T.L_ICON_RECENT_FROM_DATE,
    P.L_ICON_RECENT_TO_DATE = T.L_ICON_RECENT_TO_DATE,
    P.ACTIVE_FLAG = T.ACTIVE_FLAG,
    P.MODIFIED_BY = T.MODIFIED_BY,
    P.MODIFIED_DATE = T.MODIFIED_DATE,
    P.CATEGORY_ID = T.CATEGORY_ID,
    P.SUBCATEGORY_ID = T.SUBCATEGORY_ID,
    P.SUBJECT_ID = T.SUBJECT_ID,
    P.STATUS_ID = T.STATUS_ID
    When not matched then
    Insert (P.LINK_ID,
    P.L_URL,
    P.L_TITLE,
    P.L_DESCRIPTION,
    P.L_ISSUE_DATE,
    P.L_PUBLICATION_DATE,
    P.L_LAST_MODIFIED_DATE,
    P.L_ICON_NEW,
    P.L_ICON_RECENT,
    P.L_ICON_NEW_FROM_DATE,
    P.L_ICON_NEW_TO_DATE,
    P.L_ICON_RECENT_FROM_DATE,
    P.L_ICON_RECENT_TO_DATE,
    P.ACTIVE_FLAG,
    P.MODIFIED_BY,
    P.MODIFIED_DATE,
    P.CATEGORY_ID,
    P.SUBCATEGORY_ID,
    P.SUBJECT_ID,
    P.STATUS_ID)
    values (T.LINK_ID,
    T.L_URL,
    T.L_TITLE,
    T.L_DESCRIPTION,
    T.L_ISSUE_DATE,
    T.L_PUBLICATION_DATE,
    T.L_LAST_MODIFIED_DATE,
    T.L_ICON_NEW,
    T.L_ICON_RECENT,
    T.L_ICON_NEW_FROM_DATE,
    T.L_ICON_NEW_TO_DATE,
    T.L_ICON_RECENT_FROM_DATE,
    T.L_ICON_RECENT_TO_DATE,
    T.ACTIVE_FLAG,
    T.MODIFIED_BY,
    T.MODIFIED_DATE,
    T.CATEGORY_ID,
    T.SUBCATEGORY_ID,
    T.SUBJECT_ID,
    T.STATUS_ID)

    You cannot update the same column that is used in the join.

    The error is been derived from here:
    on (t.status_id = s.status_id)
    

    http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:556373000346392260

  • With the help of AUSST - latest updates of Adobe CC 2014 are not uploaded to the server - how to solve this problem?

    With the help of AUSST - latest updates of Adobe CC 2014 are not uploaded to the server - how to solve this problem?

    I tried both incremental and train to do a fresh install (. / AdobeUpdateServerSetupTool - root = "/ serverroot/updates / Adobe / CS '-fee)

    If anyone can answer this - please let me know.

    Hi Mark,

    Try to refresh the web server and run the AUSST with cool switch. In addition, please make sure that you have enough disk space available in the location of the server.

    Thank you

    Ashish

  • With the help of a correct sign in iD and password but nothing happens.

    With the help of a correct sign in iD and password but nothing happens - it just keeps watch as this is something but 'Hourglass' never really stops cycling!  Can I open a session / connection to Adobe on my iPad so I know that's all is OK but not on my MacPro!  Any ideas welcome... never had this before and I need to download my purchased upgrade Lightroom 4 as soon as possible! Thank you

    Hi, thanks for the suggestions - certainly connected to the internet!

    In the end, I went through the process of "update" in Mackeeper and even if there is nothing relevant that I could see - somehow I managed to connect!

    -It was strange that I never had errors on the sign in at all... but if I went through the process of the struggle to sign as a reminder of the password request, it looks like my email address / iD has not been recognized - weird because it has all the same info/details usedto sign in on my ipad and used to buy all my software recently and in the past!

  • With the help of Max for alphanumeric values

    Currently I have a column varchar2 with the following data
    NPT_Code
    NPT00001
    NPT00112
    NPT03019A
    NPT00419
    Try to find a way to remove all the letters and get the next highest value increase.

    Numbers are always set to 5. Letters from there always 3 to the left. and sometimes, there is a letter to the right.

    I was going to mak a sequence and manually to the search for the greatest number in this column and just start from there, but I was wondering if anyone else knows another solution that uses max or something simliar.
    Select Max(NPT_Code) + 1 into l_NPT_CODE FROM TABLE
    
    UPDATE TABLE
    SET NPT_CODE = L_NPT_CODE
    WHERE ID = XXXX;

    Hello

    Here's one way:

    SELECT     TO_NUMBER ( REGEXP_SUBSTR ( string_column
                              , '[[:digit:]]+'
                          )
                )     AS number_value
    FROM    table_x
    ;
    

    number_value will be the number 3019 if string column is one of the following strings:
    NPT03019A
    NPT03019
    T03019
    03019NPT
    NPT3019A
    NPT0000003019A
    03019
    3019

    You can then use number_value functions such a MAX.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

  • With the help of AfterInsertTrigger for the audit table

    Hi all

    I use after Insert trigger to re - write the record goes to the base table in the corresponding table. The statement from the two tables are the same, except that the table has a column more - audit_time. Here is how I defined the trigger:

    Create or replace trigger dup_rec after insert on table_A for each line
    begin PK_comm.create_audit_rec (table_A, table_b,: new.) ROWID); end;


    In the PK_comm package, I defined the procedure as 'PRAGMA AUTONOMOUS_TRANSACTION' create_audit_rec as follows:


    Procedure create_audit_rec (baseTable IN VARCHAR2, auditTable IN VARCHAR2, cRowId IN VARCHAR2)
    IS
    PRAGME AUTONOMOUS_TRANSACTION;

    Insert into auditTable (audit_time, col1, col2, col3)
    Select systimestamp, col1, col2, col3
    from baseTable
    where ROWID = chartorowid ('v_rowID');

    It seems that registration is NOT added to the audit table when I tried to insert a record in the database table. Is it possible that integration into baseTable have not completed when the trigger is activated? If Yes, what is the work around?

    Thanks for your help,

    Mike

    Packages have session scope. Thus, each session will have a different instance of the collection.

    If you have multiple tables, you must in general, several collections. If you can guarantee that a single table would never change during the scope of a single statement, you could get away with a single collection. But as soon as a trigger on table A changes data in table B, you would need different collections. For most applications, it is much easier to simply create separate collections. I guess you can also create a collection of objects and folders that have a table name and a ROWID as well and add the logic to process only the associated with the table ROWID that you are interested in.

    Justin

  • with the help of iTFW for the removal of tracks dead

    I prefer to use other software to manage and play my media, but still rely on iTunes for tasks (for example, to manage an iPod).  Therefore, I trust iTFW (record shows iTunes) to keep my iTunes updated library...

    I had not used iTFW for a long time since giving up my iPod, but now need to use it after having opted in iTunes Music Match.  However, now and with versions of iTunes (12.4.1.6), if I want to delete detected dead titles iTunes pushes me every time "are you sure you want to delete this song?

    Apart from iTunes may delete the file (my library is backed up), but I can't approve each deletion a track of dead... and even less of them 5800...

    Of course, I am here for suggestions as to what others can do about it and what option should I use ("Download remove" or "remove song")... but I am also looking to give their comments on all people to iTunes to Apple not wanting to manage their iTunes library...

    TIA

    Try to connect to iTunes Music Library so that iTFW only must make in the face of content stored locally which may be missing. This should prevent iTunes questions on whether to delete the downloads or remove or hide content cloud.

    You should probably clean your copies while too disconnected. See Re: I can not find my duplicates in Itunes 12.4.

    TT2

  • With the help of loudspeakers for live computer with microphone input.

    I read on here about the same problem I have but the response has been way off topic so had to ask here again. In windows XP, I could connect my microphone in my laptop and could hear myself in through computer speakers. I want to be able to do the same thing in windows vista. Can someone help me?

    Hi drwaseem,

    Welcome to Windows Vista answers Forums!

    You must Activate the Microphone

    1. connect the microphone to the computer.

    2. click on Start->-> Accessories for all programs, and then select Sound Recorder.

    3. click Start Recording (the red circle) and speak into the microphone.

    4 Recording tab showing a signal detected for the Microphone device

    Note: must have green check mark on that Microphone icon. If there is no checkmark, it means it is disabled.

    To activate the Microphone, right click on Microphone and click Activate. If you don't see the Microphone in the list, right-click on the white space and select devices see the disabled. Then, you'd see the Microphone. However, if you don't see the green check mark on it, right-click on it and click Activate. And also to select the Microphone and click on set as default (if defined as default button is active).

    For more information, you can consult the following link:

    http://Windows.Microsoft.com/en-us/Windows-Vista/connect-a-microphone-music-player-or-other-audio-device-to-your-computer

    Hope this information is useful.

    Jeremy K

    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • With the help of QProperty for a label inside the list view

    Hello

    I wanted to assign the value of a label in the list view to a string QPROPERTY. I did it using Qt.myname = _app. QPropertyName. And Qt.myname attributed to label.

    It updates correctly during installation. But if I change the value, it is not updated within the display list, but working in another label that is outside the view of the list.

    It works for me

            ListView {
                property string myCppProperty: app.cppProperty
                listItemComponents: [
                    ListItemComponent {
                        Container {
                            id: listItemContainer
                            Label {
                                text: listItemContainer.ListItem.view.myCppProperty
                            }
                        }
                    }
                ]
            }
    
  • With the help of DAC for running no BIApps infa jobs n 2 EP running in parallel

    Hello

    We already have configuration BI Apps prod environment using DAC, Informatica and OBIEE 11 g for one of our customers.

    Now, we want to check the possibility of using the DAC for the execution of BIApps no informatica related jobs.
    (That we had only a week of the execution plan of DAC weekend and Informatica and DAC are inactive most of the time during the week)

    Customer wants a separate new small datamart be configured which meet the requirements of statement for different departments and has no links of kinship or any link with existing BI Data Warehouse applications.

    I just wanted to check if it will violate the license terms (if we use CAD to workflows not BI Apps and run another EP)?

    In addition, the DAC Build 10.1.3.4.1 is capable of running two parallel execution plans?

    We have heard long back that two parallel feature EP will be lunched in the version 11g CAD. Pointers or new in this space?

    Thanks in advance,

    From what I remember, you cannot load a 'distinct' DB instance that is NO OLIVIER. If you create a small custom datamart on the INSIDE of the OLIVIER exitsing schema, then it is acceptable. However, if you use DAC (no matter if its plan one or two plans) to load a NON-OBIA target, this may violate the license agreement. You need a self-contained separate license for Informatica and use the planner of Informatica tool. If you want to use DAC, ensure that your target is inside the DW OBIA.

    Pls correct brand...

  • With the help of Vlan for LAN and DMZ

    Hello

    For the moment, I have assigned my LAN and DMZ networks to two separate network card (so therefore no Vlan tagging)

    for example vmnic0 = LAN, vmnic1 = DMZ.

    It works well but I like to make changes in the way I want to use two separate physical network adapter and use on the two s two LAN and DMZ nic but now using the VLAN.

    So think of this configuration:

    For each network, I create a Vswitch, in order to obtain a Vswitch named VsLAN, VsDMZ for the case.

    The Vswitch I attribute a two nic Nic will be the day before. as vmnic0, vmnic2 (at rest)

    This Vswitch I create a port group and assign the correct number of VLan as LAN 10 and 20 to the DMZ.

    Create the another Vswitch will have the same Nic but now vmnic0 will be the stanby one.

    Probalby all great so far I think or not?

    Issues related to the:

    -Well this concept where there is a relationship a Vswitch and port group or a switch with multiple exchanges?

    In case a Vswitch with multiple port groups I will assign to group level reserve and the active NIC Port.

    -If I create a group of ports and assiging several Vlan IP packets received by the virtual machine itself also be labelled or not identified?

    Other words. Do I need to configure the NETWORK adapter to the virtual machine also for the same local network ID virtual or not.

    Thanks for your comments.

    Hello

    Change of vlan is a pretty good idea to get the failover and the performance of the network LAN and DMZ. You have confused somewhat however concepts.

    A can only be used in a vSwitch vmnic. So what you want to do is the following:

    Create a vSwitch

    On the vSwitch create two ports: LAN (vlan10), DMZ (vlan20)

    If vmnic0 and vmnic1 have access to the vlan10 and 20, then simply add the two vmnic virtual switch. By default, they will both be active and that's fine. If you do not want to CHANGE the GRPE ports LAN and goto the "failover" tab and put vmnic0 as active and vmnic1 as before. Then do the reverse on the DMZ port group.

    Best regards

    Frank Brix Pedersen

    blog: http://www.vfrank.org

  • With the help of DVT for the anonymous user

    Hello

    Can we use DVT for customization of the user interface for the anonymous user, I need to use the PST with the user offline. Please let me know if there is a way to do

    Kind regards
    Sylvie

    Hi Sarah,.

    Not really, no. If the user is anonymous, the portal framework has no way to keep the changes he made in the database, because they cannot be associated with a single user.

    If you really want, you could automatically connect to a pre-defined user (aka. a user with the name "anonymous"). However, since everyone could be connected to the same user, changes made by anyone would be seen by everyone and users might be undo/redo each and other changes constantly.

    George

  • The help of illustrator for iOS graphic animations and frame (newbie question)

    Hey there,

    I just want to get opinions and advice.

    We develop a sidescolling 2D game and I created in illustrator 2D graphics,... so far so good, right now I have a few characters designed.

    Now for the character poses, positions and framed by picture animations... hmmmm.

    I've been looking for examples of ways to create movements of character and positions in illustrator, but as the still have not found good examples or explanations.

    Would anyone care to share (or tell me some examples) workflow allows you to create different poses and positions using character illustrator...

    (eg. should I import my work in flash to use the BONE tool?) Or do I have to create every variation in illustrator and copying my character and manipulation)

    It's really up to you. Best practices depends on the specific animation that you generate. Whether semi automating your not frame-by-frame in Flash (using the functionality of the OS), or in Illustrator (using mixtures, effect change, etc. etc), seriously, I hope that the result is always being of tweens just on a frame-by-frame. In other words, even if I've not played with it (my interest in Flash is more on scripted animations), I doubt that the animation of bone resulting will be actually programmatic in the final SWF. I think it will be actually returned in the silent individual frames. (Check this should be fairly easy to do some simple tests and checking the size of the files.)

    For example: even if a single was use BONES to animate the behavior of scanning with a dial indicator, I wouldn't with script, with a frame by frame. But if I wanted to do a connected movement of a series of related vertebrae using bone would likely benefit.

    So, if the nature of your animation is such that the inverse kinematics is advantageous, (a series of several joints) using bones in Flash would be probably more convenient, easier to change after the fact and simplifies the effects of flexibility and decay. Otherwise, if it is a simple linear movement or change in shape, you could probably do as well in Illustrator.

    Now, if the inverse kinematics (the real behavior of the BONES tool) may actually be interactive in the final SWF, it's a completely different thing.

    Whatever it is, with the exception of works of art very simple, I would tend to draw the basic shapes in a drawing program, and not in the Flash authoring environment.

    JET

  • Presented with the download page empty for update of Flash Player 13

    I tried to upgrade to Flash 13, but every time I get to the download page (http://get.adobe.com/flashplayer/) the images on the page are disappearing and I'm left with a blank page.

    I need to update this - what's happening on Earth? I hope someone can help?

    I use Windows 8 64-bit with bang up to date Firefox. I disabled Adblock Plus for the page and tried to turn off my anti-virus software to allow the download, but it is still empty.

    Download the FULL offline install:Flash Player plugin (all other browsers)

    Close Firefox, and then run.

  • With the help of Outlook for Windows on my Macbook Pro 13 "(the end of 2013)

    Help! Please, I beg you!

    I'm being forced to adopt Outlook for Windows to interface with a NetSuite product that transfers information back and forth between Outlook and NetSuite. A work requirement. And NetSuite has yet to acknowledge that everyone works in a Windows environment or on a PC.

    In an ideal world, I would like to continue to work in the environment, I am used to use (all my favorites on OS X) when switching from time to time in Outlook for Windows to activate the Netsuite interface.

    Good speed, maybe not as fast in general, I imagine running a Windows operating system parallel through something like VM Fusion would be the option the easier for me, since I go back through the day.

    I'm not an expert user, so I need to keep things simple and stable.

    Your advice would be welcome.

    Thank you very much!

    VirtualBox is free. Parallels and Fusion are commercial products. With any VM product, if you sufficient safe, you can run the Windows host OSX reviews and use Outlook for Windows in the VM to interface with Netsuite.

    Please verify that NetSuite is supported under Windows on a virtual Mac machine.

    Another option is to use Bootcamp/Windows and use a VM engine to import the BC/Windows as a virtual machine.

Maybe you are looking for