Oracle Merge 實現更新/插入記錄的自動判斷

來源:互聯網
上載者:User

在 SQL MAP 中定義這樣的 SQL ,Oracle 資料庫中, 如果有  s.post=t.post and s.FLISK_ID=t.FLIGHK_ID

這 2 個條件和傳入的資料相等的, 那麼就執行 UPDATE   SET  語句。 否則執行  INSERT 語句。

  1. merge into crs.flight_task_config s    
  2.      using (select #fliaskId# as  FLIID,#post# as post     
  3.      from dual) t    
  4.      on    
  5.      (s.post=t.post and s.FLISK_ID=t.FLIGHK_ID )   
  6.      when  matched then update    
  7.         set   s.PERSONS = #persons:DECIMAL#,   
  8.               s.LAST_MODIFIER = #lastModifier:DECIMAL#,   
  9.               s.LAST_MODIFY_TIME = SYSDATE,   
  10.               s.IF_LINGYAN = 'NO'  
  11.         when not matched then    
  12.         insert (   
  13.             s.TASFIG_ID,   
  14.             s.FLIGASK_ID,   
  15.             s.POST,   
  16.             s.PERSONS,   
  17.             s.LAST_MODIFIER,    
  18.             s.LAST_MODIFY_TIME,   
  19.             s.IF_LINGYAN)   
  20.                 values (   
  21.              crs.SEQ_fligconfig.Nextval,   
  22.              #fligkId:DECIMAL#,   
  23.              #post:VARCHAR#,   
  24.              #persons:DECIMAL#,   
  25.              #lastModifier:DECIMAL#,   
  26.              SYSDATE,   
  27.              'NO')     

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.