I have a really simple question, is it possible to update a table with new values using just one update statement.
Say for example I have a table with author, title, date, popularity. Now I got some new data which has author name, title corresponding new popularity. How do I update the table now in one statement. Note that author and title are not unique.
You can do it in a single statement using Oracle's MERGE statement:
MERGE DestinationTable target
USING (
Select 'Briggs' Author, 'My Next Master' Title, 6 Popularity
Union All Select 'Millis', 'Man up, Nut head', 3
) Z
ON Z.Author = target.Author
And Z.Title = target.Title
WHEN MATCHED THEN
UPDATE SET target.Popularity = Z.Popularity
WHEN NOT MATCHED THEN
Insert(Author, Title, Popularity) Values(Z.Author, Z.Title, Z.Popularity);
Oracle's MERGE statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With