Merge Statement

From: Mtek <mtek_at_mtekusa.com>
Date: Mon, 2 Feb 2009 12:06:42 -0800 (PST)
Message-ID: <58e3b6eb-b801-49bf-9ca5-4b64bf503fb9_at_i18g2000prf.googlegroups.com>


I have this merge statement:

     MERGE INTO rank_history_new zrh
       USING (SELECT v_id AS new_m_ticker, v_rec.z_rank_d AS new_rank
FROM dual) zrh2
         ON (zrh.m_id = v_id AND rank = v_rec.z_rank_d)
       WHEN NOT MATCHED THEN
         INSERT (m_id, rank, time, add_del_flag)
         VALUES (v_id, v_rec.z_rank_d, v_rank_date, v_add_del_flag);

It does not work 100%. Actually what I want is to compare it with the LAST entry for the v_id. So, if I have the following. So if there are 4 entries for a given ID, I want to compare it against the last entry.

Can this be done? I'd like to use MERGE rather than having to do a select, then a separate compare to decide if I need to insert.....etc.... Received on Mon Feb 02 2009 - 14:06:42 CST

Original text of this message