现在的位置: 首页 > 综合 > 正文

Oracle数据库merge into

2013年03月11日 ⁄ 综合 ⁄ 共 352字 ⁄ 字号 评论关闭
-- Oracle数据库 
-- SQL说明 : 将source_tb中的数据merge到target_tb表中
-- 	         source_tb中存在同target_tb主键相同的记录时,更新target_tb表
--           source_tb不存在同target_tb主键相同的记录时,插入target_tb表
-- SQL正文 : 
merge into target_tb t using source_tb s   
    on (t.pk = s.pk)  --执行条件 
when matched then     --如果数据存在,更新数据 
    update set t.name = s.name,t.address = s.address  
when not matched then --如果数据不存在,插入数据 
    insert (t.name,t.address) values (s.name,s.address)

 

抱歉!评论已关闭.