mysql 存储过程参数传入字符串报错
在创建了一个如下所示的 mysql 存储过程后,你会遇到一个错误:
create procedure mypo02(in dataname varchar(10)) begin if dataname is null or dataname = "" then select * from ssd; else select * from ssd where ename like concat('%',dataname,'%'); end if; end;
错误信息为:
procedure execution failed 1054 - unknown column '王小李' in 'field list'
问题在于:调用存储过程时传入的 dataname 参数类型不匹配。
当 dataname 参数为整型时,存储过程可以正常运行。但当 dataname 参数为字符串时,由于 where 子句中的字段类型为整型,就会导致错误。
要解决此问题,你需要确保调用存储过程时传入的参数类型与存储过程定义中指定的类型相匹配。具体来说,你需要将 dataname 改为字符串类型,如下所示:
call mypo02('王小李')
如果问题仍然存在,请提供更详细的错误信息或代码片段,以便进一步分析解决。
以上就是MySQL 存储过程传入字符串参数报错:为什么传入字符串会报错?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号