同一个表,有就更新无则插入,一条SQL实现

----有就更新无则插入
MERGE INTO T_PAY_TYPE_LEVEL A
USING (select count(*) count
         from T_PAY_TYPE_LEVEL
        where agent_id = 5502302
          and salary_type_id = 1) b
on (b.count <> 0)
WHEN MATCHED THEN
  UPDATE
     SET A.level_id = 1, a.grade_id = 1, a.update_time = date '2008-12-23'
WHEN NOT MATCHED THEN
  INSERT VALUES (1230013390, 5502302, 1, 1, 1, date '2008-12-23');

参考:http://xo-tobacoo.iteye.com/blog/182791

你可能感兴趣的:(sql,Blog)