![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi all! I would like to use the db2 merge statement submitting it as a statement from jdbc. I am in the following scenario. I'm working with a proprietary persistence layer and I'm handling an entity I don't know whether it's already persisted or not and I would like to use the merge statement in order to insert or update a row on the database. Is it possible? Suppose I'm working with the table people with three columns: id, name, surname and I'm handling an entity with id="5", name="chuck", surname="norris" Am I able to issue: MERGE INTO people AS t * USING (select '5' as id, 'chuck' as name, 'norris' as surname from SYSIBM.SYSDUMMY1)As s * * ON (t.id = s.id) * WHEN MATCHED THEN * * * UPDATE SET t.name=s.name, t.surmane=s.surname * WHEN NOT MATCHED THEN * * INSERT * * * (id, name, surname) * * VALUES (s.id, s.name, s.surname) such a statement? I'm trying to do that but I got an error. I don't think it's allowed to use a select after USING: USING (select '5' as id, 'chuck' as name, 'norris' as surname from SYSIBM.SYSDUMMY1)As s I also tryed to do: USING VALUES('5','chuck','norris') AS s(id,chuck,norris) but maybe I was wrong with the syntax and it dosn't work. Any help would be appreciated. Thanks Fil |
#4
| |||
| |||
|
|
MERGE INTO people AS t USING (select '5' as id, 'chuck' as name, 'norris' as surname from SYSIBM.SYSDUMMY1)As s ON (t.id = s.id) WHEN MATCHED THEN UPDATE SET t.name=s.name, t.surmane=s.surname WHEN NOT MATCHED THEN INSERT (id, name, surname) VALUES (s.id, s.name, s.surname) such a statement? I'm trying to do that but I got an error. I don't think it's allowed to use a select after USING: |
|
USING (select '5' as id, 'chuck' as name, 'norris' as surname from SYSIBM.SYSDUMMY1)As s I also tryed to do: USING VALUES('5','chuck','norris') AS s(id,chuck,norris) |
![]() |
| Thread Tools | |
| Display Modes | |
| |