前言
将数据从一张表迁移到另外一张表的过程中,通过mysql的concat方法批量生成sql时遇到了一个问题,即进行UPDATE更新操作时如果原表中的字段中包含单引号'或者双引号",那么就会生成不正确的...实践
学生表student中有以下四条数据,现在要把student表中的四条数据按照id更新到用户表user当中,user表的结构同student一样。...函数介绍:replace(object,search,replace),把object对象中出现的的search全部替换成replace。...replace(name,"'","\\\'"),"\"","\\\""),"' where id = ",id,";") from student where id = 2;
对student整表应用以下...sql
select concat("update user set name = '",replace(replace(name,"'","\\\'"),"\"","\\\""),"' where id