Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Merge Oracle: how to use merge without update

Pranav.shahJul 21 2015 — edited Jul 21 2015

Sql Developer 11g

i am following this for merge http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606

now from this i only want to use Delete and Insert(i do not want to update)

Table Structure:

CREATE TABLE bonuses (employee_id NUMBER, bonus NUMBER DEFAULT 100);  INSERT INTO bonuses(employee_id) (SELECT e.employee_id FROM employees e, orders o WHERE e.employee_id = o.sales_rep_id GROUP BY e.employee_id); 

Simple Merge:

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);

Is there any way that i can use insert and delete only from MERGE statement.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2015
Added on Jul 21 2015
13 comments
2,059 views