![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I would like to use MERGE to upsert some simple values. Here's what I've got, which works fine with all my tests, but MERGE is pretty complicated and I want to make sure I've got my tiny brain around the problem. Is this a reasonable way to do this? Is there a better way? Many TIA! Mark create or replace procedure ups(xa number) as begin merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; end ups; / drop table mergetest; create table mergetest(a number, b number); call ups(10); call ups(10); call ups(20); select * from mergetest; A B ---------------------- ---------------------- 10 2 20 1 |
#3
| |||
| |||
|
|
I would like to use MERGE to upsert some simple values. Here's what I've got, which works fine with all my tests, but MERGE is pretty complicated and I want to make sure I've got my tiny brain around the problem. Is this a reasonable way to do this? Is there a better way? Many TIA! Mark create or replace procedure ups(xa number) as begin merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; end ups; / drop table mergetest; create table mergetest(a number, b number); call ups(10); call ups(10); call ups(20); select * from mergetest; A B ---------------------- ---------------------- 10 2 20 1 |
#4
| |||
| |||
|
|
I would like to use MERGE to upsert some simple values. Here's what I've got, which works fine with all my tests, but MERGE is pretty complicated and I want to make sure I've got my tiny brain around the problem. Is this a reasonable way to do this? Is there a better way? Many TIA! Mark create or replace procedure ups(xa number) as begin merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; end ups; / drop table mergetest; create table mergetest(a number, b number); call ups(10); call ups(10); call ups(20); select * from mergetest; A B ---------------------- ---------------------- 10 2 20 1 |
#5
| |||
| |||
|
|
I would like to use MERGE to upsert some simple values. Here's what I've got, which works fine with all my tests, but MERGE is pretty complicated and I want to make sure I've got my tiny brain around the problem. Is this a reasonable way to do this? Is there a better way? Many TIA! Mark create or replace procedure ups(xa number) as begin merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; end ups; / drop table mergetest; create table mergetest(a number, b number); call ups(10); call ups(10); call ups(20); select * from mergetest; A B ---------------------- ---------------------- 10 2 20 1 |
#6
| |||
| |||
|
|
merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; A B ---------------------- ---------------------- 10 2 20 1 Without you stating the business rules how can we know if what your statement is doing corresponds with your goal? |
#7
| |||
| |||
|
|
merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; A B ---------------------- ---------------------- 10 2 20 1 Without you stating the business rules how can we know if what your statement is doing corresponds with your goal? |
#8
| |||
| |||
|
|
merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; A B ---------------------- ---------------------- 10 2 20 1 Without you stating the business rules how can we know if what your statement is doing corresponds with your goal? |
#9
| |||
| |||
|
|
merge into mergetest m using dual on (a = xa) when not matched then insert (a,b) values (xa,1) when matched then update set b = b+1; A B ---------------------- ---------------------- 10 2 20 1 Without you stating the business rules how can we know if what your statement is doing corresponds with your goal? |
#10
| |||
| |||
|
|
There are working demos of MERGE in Morgan's Library at www.psoug.org that may help you understand how it works. |
![]() |
| Thread Tools | |
| Display Modes | |
| |