insert&update

begin
insert into a(id,name,address)
 select b1.id,b1.name,b1.address from 
        (select #{id} as id,#{name} as name,#{address} as address from dual) b1 
          where not exist(select 1 from a a1 where a1.id =#(id));

update a set(id,name,address)=select b1.id,b1.name,b1.address from 
        (select #{id} as id,#{name} as name,#{address} as address from dual) b1 
          where not exist(select 1 from a a1 where a1.id =#(id));
end;

注意,begin end如果不加的话,可能会报无效索引,插入,更新失败。

posted @ 2022-07-05 14:14  景伟·郭  阅读(38)  评论(0)    收藏  举报