When doing a MERGE in Oracle SQL, how can I update rows that aren't matched

Hi,
create table TEST1
History_date Date,
ID NUMBER not null
create table TEST2
ID NUMBER not null,
History_date Date,
We_history_date Date
Can we do like this...
merge into test2 t2
using
test1 t1
ON (t1.id = t2.id)
when matched
update set t2.We_history_date = t1.history_date
when not matched
update set t2.We_history_date = NVL(t2.we_history_date,SYSDATE);Thanks,
Edited by: 960736 on Sep 27, 2012 2:05 PM

There is nothing to update if there is no match.
You need to INSERT a new record.
See the Examples section of the MERGE statement in the SQL Language doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
>
Examples
Merging into a Table: Example The following example uses the bonuses table in the sample schema oe with a default bonus of 100. It then inserts into the bonuses table all employees who made sales, based on the sales_rep_id column of the oe.orders table. Finally, the human resources manager decides that employees with a salary of $8000 or less should receive a bonus. Those who have not made sales get a bonus of 1% of their salary. Those who already made sales get an increase in their bonus equal to 1% of their salary. The MERGE statement implements these changes in one step:
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000);

Similar Messages

  • How can i update rows  in a table based on a match from a select query

    Hello
    How can i update rows in a table based on a match from a select query fron two other tables with a update using sqlplus ?
    Thanks Glenn
    table1
    attribute1 varchar2 (10)
    attribute2 varchar2 (10)
    processed varchar2 (10)
    table2
    attribute1 varchar2 (10)
    table3
    attribute2 varchar2 (10)
    An example:
    set table1.processed = "Y"
    where (table1.attribute1 = table2.attribute1)
    and (table1.attribute2 = table3.attribute2)

    Hi,
    Etbin wrote:
    Hi, Frank
    taking nulls into account, what if some attributes are null ;) then the query should look like
    NOT TESTED !
    update table1 t1
    set processed = 'Y'
    where exists(select null
    from table2
    where lnnvl(attribute1 != t1.attribute1)
    and exists(select null
    from table3
    where lnnvl(attribute2 != t1.attribute2)
    and processed != 'Y'Regards
    EtbinYes, you could do that. OP specifically requested something else:
    wgdoig wrote:
    set table1.processed = "Y"
    where (table1.attribute1 = table2.attribute1)
    and (table1.attribute2 = table3.attribute2)This WHERE clause won't be TRUE if any of the 4 attribute columns are NULL. It's debatable about what should be done when those columns are NULL.
    But there is no argument about what needs to be done when processed is NULL.
    OP didn't specifically say that the UPDATEshould or shouldn't be done on rows where processed was already 'Y'. You (quite rightly) introduced a condition that would prevent redo from being generated and triggers from firing unnecessarily; I'm just saying that we have to be careful that the same condition doesn't keep the row from being UPDATEd when it is necessary.

  • How can I update apps that were purchased through old unassailable email address?

    How can I update apps that were purchased under an old unassailable email address? 

    If you have the pasword for it then its not an issue, if you dont you may need to contact apple suport

  • How can we update current ins value to match insurance depr area?

    Hello - I need some advice, please.  On an asset that was transferred within a company code, the current insurable value on the insurance tab in master data is showing DOUBLE the insurance value that is showing in the insurance depreciation area.  How can we update the current insurable value to the correct amount?  Thank you for your help.
    Heidi

    Hi,
    As advised above by Bernhard, you should not select COPY check box in the below path.
    SPRO -> FA-> AA-> Master Data -> Screen Layout -> Define Screen Layout for Asset Master Data -> Define Screen Layout for Asset Master Data....
    Here select the screen layout, which is assigned to the questioned asset's asset class and click on LOGICAL FIELD GROUPS.
    Select LFG 08 - Insurance and click on FIELD GROUP RULES.
    For the field groups 62, 64, and 78, you should deselect check box COPY and SAVE.
    Cheers,
    Srinu

  • How can I delete bookmarks that aren't in a folder (unorganized)?

    When I click on "Organize Bookmarks" I don't find a way to get to the bookmarks that aren't organized into a folder. I'd like to delete some and to sort others into the folders, but none of these show up. There is an item in the left bar named "Unorganized Bookmarks" but when I highlight it, it shows nothing as if it were empty. Is there another way I can access those single bookmarks to sort them and delete them?
    Thank you!
    Christopher

    Crazy K,
    If you want to burn them, you need to have the song files physically on your local drive.
    If they were purchased from one of the online stores that allows re-downloading (Amazon Digital Music, iTunes Store, etc.), just download new copies.

  • I often get transfer errors -10608 and -10803 when doing double buffered analog output. How can I fix this?

    I'm using the PCI 6711 board programmed in Visual Basic. I'm working from the WFMDoubleBuf example file for VB and I've modified it for continuous output on 2 analog channels. I fill the buffers with customized waveforms from files I have previously created. I often get -10608 (noTransferInProgError, No transfer is in progress for the specified resource) and -10803 (transferStoppedError   , The on-going transfer has been stopped. This is to prevent regeneration for output operations, or to reallocate resources for input operations) errors when I try to output at higher rates (about 140000samples per second and up). The -10608 error generally happens after seve
    ral (sometimes hundreds) of half buffers have been transfered, whereas the -10803 error usually occurs immediately after starting output. This device is supposed to be able to output at up to 1Msample per sec per channel but I don't seem to be able to do that. I have tried increasing the buffersize (up to 16777216) with no apparent effect. Is there any other information as to what causes these errors or how they can be avoided. Any ideas?

    Roz,
    I found two KnowledgeBase entries about the most common causes of these errors.
    1. Why Do I Receive the Error -10608 When Using the PCI-6711?: http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/37752a79eb6a950886256c8b006e8870?OpenDocument
    2. Why am I Getting the 10800 and/or 10803 Errors?:
    http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/c9097c72463d215886256a700075a6ef?OpenDocument
    Have a great day.

  • How can I update the artwork on iTunes Match?

    When I enabled iTunes Match I had some music that had some album covers that didnt' match or were low resolution.  The album art was embedded on the MP3. 
    I have gone back through my local collection and updated the atwork (removed the embeded art and had iTunes get the artwork).  Now however when I go and look at my iTunes Match songs on another computer or device those album covers did not get upgraded as well.  Is there a process that I need to do to trigger an updat to the iTunes Match service?
    Thanks,
    -Matt

    "I have noticed if the music in your iTunes have album art and you copy that to the iPod it shows up. But any that you have just copied to the iPod without going through iTunes won't show up"
    That is how it's supposed to work. The artwork is stored in an artwork folder in iTunes. It needs to be there to transfer across to the iPod and be viewable.

  • How can I update programs that were purchased for me?

    I received a laptop that was preloaded with Final Cut Pro and Motion. I have updated the OS to 10.9.1 and when I try to install upates for FCP and Motion I get the Apple ID for the person who installed the original programs and no way to change it to my ID. Is there an easy way to transfer them to my ID so I can continue with the updates?
    Thanks,
    Paul

    There's no way at all except to delete them and then buy them from your Apple ID.
    (97379)

  • How can I update the x-axis to match a time reading in a waveform chart?

    I am recording data in real time and displaying it in a waveform chart. However, I have yet figured out how scale the x-axis to match the actual time scale of my data. I've played with the accompanying property node but that has not produced the desired result. My guess is that there is a combination of xscale.range.maximum and xscale.multiplier values that need to get updataed in a certain way, but how is still unknown to me. If you could assist I'd appreciate it.

    Nobody has recomended using a Waveform Chart!
    A waveform chart will plot the points based on the "t0" of the waveform.
    The waveform chart will maintain the buffer so all you have to do is apply the new data.
    The "t0"'s of updates from more than one plot do not have to match-up.
    See the attached LV7.0 example and jpg.
    Ben
    Note:
    "t0" values for an individual plot must be increasing values.
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Wform_Times.vi ‏58 KB
    Wform_Times.JPG ‏102 KB

  • How can I update apps that were installed using another Apple ID

    I have an ipad that was set up by my school. I use my own apple ID however it came preinstalled with Pages, Keynote and Numbers. However according to my app store these apps need to be updated. I press update and insted of asking me for MY apple ID, it asks for the schools.
    Is there a way of updating this app with out needing to schools apple ID password. The guy that created it has since left and no-one knows what he set the password to.
    Thanks

    Delete and redownload them.
    (106884)

  • How can I update iPhoto that's locked to another user?

    I bought a MacBook Air from a friend but iPhoto is still connected to his Apple ID. Updating iPhoto is not possible any more. Even though I own the computer and the preinstalled software.
    The error message (translated from German): "Updates for other accounts available. Login with [email protected] to update software for this account."

    You need to ask your friend to call AppleCare and get the Mac and the preinstalled iLife apps released from his ID.

  • HT204053 I have downloaded icloud to my pc, however when i go to sign in to Apple through icloud, i get an error message saying my apple ID is valid but is not an icloud account. What does this mean and how can i update my account so i can access icloud?!

    I have downloaded icloud to my pc, however when i go to sign in to Apple through icloud, i get an error message saying my apple ID is valid but is not an icloud account. What does this mean and how can i update my account so i can access icloud?!

    To use iCloud, you must first set it up with your Apple ID on a device with iOS 5 or a Mac with OS X Lion.

  • I have a really old Itunes account.  I no longer have the email and when I go to put in my birthday it is coming up wrong because the birthday on the account does not have a year.  How can I fix this?

    I have a really old Itunes account.  I no longer have the email and when I go to put in my birthday it is coming up wrong because the birthday on the account does not have a year.  How can I fix this?  I have about 70 downloaded songs on this log in that I would like to get back.
    Thank you in advance.

    Contact iTunes customer support.

  • HT203176 When I delete a file, it does not appear in the Trash - How can I fix this. Its a brand new MacBook Pro 17'

    When I delete a file, it does not appear in the Trash - How can I fix this. Its a brand new MacBook Pro 17''

    http://www.thexlab.com/faqs/trash.html for starters.

  • Negative (to inline a letter or to thin it) offset path does not work in Illus-CC 2014 (when preview is on- nothing happens). How can I get this to work like in previous versions.

    Negative (to inline a letter or to thin it) offset path does not work in Illus-CC 2014 (when preview is on- nothing happens). How can I get this to work like in previous versions.

    Thanks for your quick reply. I tried a number of different values. Usually when I do a negative offset they're very small values, like -.25 or -.5.
    An Update- I took the art work into Ai CS 6 and It still did not work, which is really strange. And I've used it hundreds of times with success in the past. Also I tried it with live type and outlines, ungrouped, un-compounded still could not get it to negative offset.
    Thanks for the help.

Maybe you are looking for

  • DVI to ADC adapter to MacBook Pro

    Hello with a question. I have a 23" Apple Cinema Display, and would like to use it as an external monitor on my MacBook Pro running OS 10.7.5, on a 2.3 GHz Intel Core i5 with 4 GB memory.   I also have a G5 desk top which runs the 23" Cinema Display

  • Ipod touch not being recognized by Windows

    First of all sorry if my english will not be good enough, I'm italian :P Well, yesterday I updated my itunes to 9.0 version and i tried to sinch my ipod touch.. When I put my ipod touch into the USB door it gives me this error: He says that the APPLE

  • IPod Touch will Not Charge/Connect to Computer

    So, my iPod Touch 4G running ios 5.1.1 will not charge/connect to iTunes on my computer. It charges everywhere else but not on my computer. I even tried another charger. My computer says all my devices are up to date. But I can't find the 'Apple Driv

  • HP Touchsmart Photo isn't working

    When I open Touchsmart Photo it has a few pictures in it and a bunch of spaces with no pictures.  It won't allow me to open any of the pictures to edit.  It says "cannot view the file because the program cannot find it"  I think that may be because t

  • Help on Crossjoin Syntax Please on ASO Allocation

    Hi, Tyring to run an ASO Allocation via MaxL. I always have trouble with syntax on CrossJoins for some reason. When I run the below I get an error: ERROR - 1260052 - Syntax error in input MDX query on line 1 at token ')' . ERROR - 1241192 - Allocatio