Cobain yang ini nih,


BEGIN
   MERGE INTO emp_target et
      USING ( SELECT * FROM emp_source ) es
      ON    ( et.empno = es.empno )
   WHEN MATCHED THEN
   UPDATE
      SET et.ename  = es.ename
      ,   et.sal    = es.sal
      ,   et.mgr    = es.mgr
      ,   et.deptno = es.deptno
   WHEN NOT MATCHED THEN
   INSERT
      ( et.empno, et.ename, et.sal, et.mgr, et.deptno )
      VALUES
      ( es.empno, es.ename, es.sal, es.mgr, es.deptno );
   DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows merged.');
END;
/




On 7/4/07, Jemmy <[EMAIL PROTECTED]> wrote:
>
>   Halo...
> Numpang tanya, bagaimana caranya kalo di Oracle saya ingin mengeksekusi
> query dengan logika sebagai berikut:
>
> If exist then
> update
> else
> insert new
> end if
>
> Jadi, kalo data yang akan disave sudah ada, maka secara otomatis akan
> diupdate, kalo tidak ada baru insert new.
>
> Hasil googling ketemu pake statement MERGE, tapi setelah saya coba gak
> berhasil, bahkan error.
>
> Thx b4.
>
> Jemmy H. Tecoalu
> Personal blog: http://jemmyt.blogspot.com
>
> "The present was affected by the past, and the present will affect the
> future."
>
> ---------------------------------
> Sucker-punch spam with award-winning protection.
> Try the free Yahoo! Mail Beta.
>
> [Non-text portions of this message have been removed]
>
>  
>


[Non-text portions of this message have been removed]

Kirim email ke