码迷,mamicode.com
首页 > 数据库 > 详细

Oracle merge

时间:2016-04-11 20:34:08      阅读:296      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!