之前写了oracle拼接sql是用“||”,那么mysql也有自己的拼接的语法concat()
concat()的基本语法是如下:
括号内的拼接内容语法和python中拼接显示字符串和变量、常量时一样,字符串用引号""引起来,表字段直接写字段名,之间使用逗号隔开;
示例:
select concat("字符串",数据库表字段,"字符串") from tablename #字符串和表字段无数量、顺序限制
如:删除指定数据库mysql的表
SELECT concat('drop table ','mysql.',table_name,';') sql拼接结果 FROM information_schema. TABLES WHERE table_schema = 'myqsql'
拼接结果如下