首页 > 数据库技术 > 详细

Oracle merge

时间:2016-04-11 20:33:58      阅读:355      评论:0      收藏:0      [点我收藏+]

oracle merge

語法:

技术分享

用途:

       Use the MERGE statement to select rows from one or more sources for update or
insertion into a table or view. You can specify conditions to determine whether to
update or insert into the target table or view.

        It lets you avoid multiple INSERT, UPDATE, and DELETE DML statements

用於從一個或多個原表查詢數據插入或者更新目標表。避免多次執行insert,delete,update操作

例子:

MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000);

這裡稍微提醒下,insert後面沒有into

Oracle merge

原文:http://www.cnblogs.com/guilingyang/p/5379825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!