要把EXCEL 中的内容 转换成MYSQL 语句 导入到数据库中,于是找来找去 找到了 CONCATENATE函数
主要的就是:
1.将你想要另外添加的字符用双引号引起来 不同的列之间用逗号分隔。
以下目的就是将 A1 转换成 '周三'
A2转换成501660
A3转换成'DX02'
("insert into usercode values(" 其实转换成了 insert into usercode values(
而那些 引号 逗号 全部都需要用"" 分开来。
1)每一项需要用逗号分开,包括"A1" 需要折分为 ",a1,"
,"'",A1,"'" 第一个逗号为将前一项分开的符号,而"'"为添加单引号
=CONCATENATE("insert into usercode values(","'",A1,"'",",",B1,",","'",C1,"'",",","'",D1,"'",")",";")
=CONCATENATE("insert into usercode values(","'",A1,"'",",",B1,",","'",C1,"'",",",D1,",","'",E1,"'",",","'",F1,"'",",","'",G1,"'",")",";")
一个字符串类型需转换为:注:分隔项不需要添加引号。
,",","'",Ax,"'", |
第三个逗号依旧为分隔项逗号,第四个加双引号号的逗号为需要转换出来的逗号,
第五,第六都为分隔逗号,第七个加双引号的逗号为转换出来的逗号,最后为分隔项
如果需要转交数字类型只需要在前后加2逗号就可以 如下:501660
,",",b1,",",
insert into usercode values('周三',501660,'DX02','DX0202');
A B C D
艾娜 | 501633 | DX02 | DX0202 | insert into usercode values('艾娜',501633,'DX02','DX0202'); |
东坡 | 501634 | DX02 | DX020801 | insert into usercode values('东坡',501634,'DX02','DX020801'); |
=CONCATENATE("delete from donson_usercode where user_code=",A1,";") 注: A1为主键