时间:2021-07-01 10:21:17 帮助过:38人阅读
2、ON DUPLICATE KEY UPDATE 先更新数据,如果数据不存在时进行insert
insert into t_param (param_name, param_value) values (#{paramName}, #{paramValue}) ON DUPLICATE KEY UPDATE param_name = #{paramName},param_value = #{paramValue}
3、判断需要插入的数据是否存在,如果不存在时就插入,否则直接执行更新
INSERT INTO t_param (param_name,param_value) SELECT #{paramName},#{paramValue} FROM DUAL WHERE NOT EXISTS (SELECT param_value FROM t_param WHERE param_name = #{paramName}); UPDATE t_param SET param_value = #{paramValue} WHERE param_name = #{paramName}
mysql 无数据插入,有数据更新
标签:mys exists dual insert mysq value val row serve