MERGE INTO table_master m
USING (SELECT id
, str_cd
, slip_no
, SUM(tot_qty) AS tot_qty
, SUM(tot_amt) AS tot_amt
, sysdate AS reg_date
FROM table_detail
WHERE slip_no = vSlip_no
AND str_cd = vStr_cd
AND id = vId
GROUP BY id, str_cd, slip_no
) d
ON (m.slip_no = d.slip_no AND
m.str_cd = d.str_cd AND
m.id = d.id )
WHEN MATCHED THEN
UPDATE SET m.tot_qty = d.tot_qty
, m.tot_amt = d.tot_amt
, m.reg_date = d.reg_date
WHEN NOT MATCHED THEN
INSERT ( id, str_cd, slip_no, tot_qty, tot_amt, reg_date)
VALUES (d.id, d.str_cd, d.slip_no, d.tot_qty, d.tot_amt, d.reg_date)
;