Re: Merge Statement

From: ddf <>
Date: Mon, 2 Feb 2009 13:12:49 -0800 (PST)
Message-ID: <>

On Feb 2, 2:06 pm, Mtek <> wrote:
> 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)
>          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....

What do you mean by 'last entry', since a heap table has no order? Are these values sequenced, dated, both? Is there some definitive way to order these results to ensure you're comparing against what you consider the 'last entry'?

David Fitzjarrell Received on Mon Feb 02 2009 - 15:12:49 CST

Original text of this message