【问题标题】:when matched then insert in merge匹配时插入合并
【发布时间】:2020-09-29 11:08:36
【问题描述】:

我试过这个 sql

merge into params t
using (
    select '9158075153713931109' ATTR_ID, '9158310272413033579' OBJECT_ID,
'9158075157713931109' LIST_VALUE_ID
from dual
    where exists (select * from attributes where attr_id = 9158075153713931109)
       ) v
on (t.object_id = v.object_id)
when matched then insert (attr_id, object_id, list_value_id, show_order) values(v.attr_id,v.object_id, v.LIST_VALUE_ID,1);

只有当 attr_id (9158075153713931109) 存在时,我才需要将值插入到参数中。 我理解只有更新和删除才能与“匹配时”一起使用 请帮助我如何通过合并来做到这一点。

【问题讨论】:

    标签: sql oracle sql-update subquery sql-insert


    【解决方案1】:

    只有在 attr_id (9158075153713931109) 存在时才需要将值插入到参数中

    我看不出merge 声明的意义。据我了解您的问题,您的要求翻译为:

    insert int params (attr_id, object_id, list_value_id, show_order) 
    select s.*, 1
    from (select '9158075153713931109' attr_id, '9158310272413033579' object_id, '9158075157713931109' list_value_id from dual) s 
    where exists (select 1 from attributes a where a.attr_id = s.attr_id)
    

    【讨论】:

      猜你喜欢
      • 2012-08-09
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 2017-05-31
      • 2020-03-22
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多