匹配时插入合并
when matched then insert in merge
我试过这个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) 存在时将值插入到参数中。
我只知道更新和删除与“匹配时”一起使用
请帮助我如何使用 merge 执行此操作。
I need to insert the value into params only when attr_id (9158075153713931109) exists
我看不到 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)
我试过这个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) 存在时将值插入到参数中。 我只知道更新和删除与“匹配时”一起使用 请帮助我如何使用 merge 执行此操作。
I need to insert the value into params only when attr_id (9158075153713931109) exists
我看不到 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)