背景:在进行SQL语句编写时,我们经常会遇到大量的同时进行Insert/Update的语句 ,也就是说当存在记录时,就更新(Update),不存在数据时,就插入(Insert)。

比如现在有张J_USER这张表,

oracle merge into的用法

T_USER表

oracle merge into的用法

用 J 表 的数据 来更新 T 表的数据

MERGE INTO t_user t using (select * from j_user j) b on (t.id = b.aid)
when matched then
     update set t.year = b.year
when not matched then
     insert (t.id ,t.name,t.year) values(b.aid,b.name,b.year);
 

可以理解为 使用j_user 这张表关联, 条件是 t.id=b.aid  条件成立的时候 执行 update, 否则 insert

执行结果如下:

oracle merge into的用法

--------------------------------------------------------------------------------------------

 

相关文章:

  • 2021-06-07
  • 2021-11-30
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2021-09-30
相关资源
相似解决方案