Mysql 获取动态sql执行结果失败

ckliu_soft 2017-12-06 09:22:16
SET m = CONCAT(N'SELECT COUNT(*) INTO @columnExistsCache FROM information_schema.columns WHERE UPPER(TABLE_SCHEMA) = UPPER('',tableSchema,'') AND UPPER(TABLE_NAME) = UPPER('',tabName,N'')  AND UPPER(COLUMN_NAME) = UPPER('',columnName,'');');
SET @sqlStr = m;
PREPARE stmt FROM @sqlstr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET columnExists = @columnExistsCache;


通过动态sql方式判断列是否存在,但是select into @para 的方式无法获取到返回值,求大神指点。
...全文
180 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2017-12-06
  • 打赏
  • 举报
回复
没问题啊
set @a=null;prepare st from 'select count(*) into @a from information_schema.columns'; execute st; deallocate prepare st; select @a;
mysql> set @a=null;prepare st from 'select count(*) into @a from information_schema.columns'; execute st; deallocate prepare st; select @a; Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Statement prepared Query OK, 1 row affected, 2 warnings (0.04 sec) Query OK, 0 rows affected (0.00 sec) +------+ | @a | +------+ | 3532 | +------+ 1 row in set (0.00 sec)
ckliu_soft 2017-12-06
  • 打赏
  • 举报
回复
找到原因了,动态传参时,参数的前后需要加入转义单引号。

56,675

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧