merge into a using b on (a.USER_NO=b.USER_NO) when matched then update set a.NAME=b.NAME when not matched then insert values (b.USER_NO,b.NAME)
--用merge Merge into ta a using tb b on (a.id = b.id) when matched then update set a.name=a.name when not matched then insert(a.id,a.name) values(b.id,b.name);
我需要写一个程序,程序中用到sql,而值是未定的,例如insert into A valuse(?,?);update A set id=?,name=?.这个应该怎么写呢?谢谢!
1楼速度好快假设你要插入的记录是(user_no,name) '1','Jack' 将b改下可以写成(select '1' user_no, 'Jack' name from dual) b
merge into a using (select 5 t1 from dual) b on (a.t1= b.t1) when matched then update set a.t2= 'aaaa' when not matched then insert values ('test', b.t1) 需要注意的是 ,a.t1是条件,所以不能更新他ziduan
merge into a using (select ? user_no, ? name from dual) b on (a.USER_NO=b.USER_NO) when matched then update set a.NAME=b.NAME when not matched then insert values (b.USER_NO,b.NAME) ;这样不可以吗?
when matched then update set a.NAME=b.NAME
when not matched then insert values (b.USER_NO,b.NAME)
Merge into ta a
using tb b
on (a.id = b.id)
when matched then update set a.name=a.name
when not matched then insert(a.id,a.name)
values(b.id,b.name);
将b改下可以写成(select '1' user_no, 'Jack' name from dual) b
using (select 5 t1 from dual) b
on (a.t1= b.t1)
when matched then
update set a.t2= 'aaaa'
when not matched then
insert values ('test', b.t1)
需要注意的是 ,a.t1是条件,所以不能更新他ziduan
using (select ? user_no, ? name from dual) b
on (a.USER_NO=b.USER_NO)
when matched then
update set a.NAME=b.NAME
when not matched then
insert values (b.USER_NO,b.NAME) ;这样不可以吗?
你是正确的,thank you~!~~