MySQL WHERE-condition in procedure ignored

本小妞迷上赌 提交于 2020-01-04 09:22:12

问题


I am trying to make a procedure with arguments. But when I use them in a WHERE condition it is like there were never there. They are simply ignored.

DELIMITER //

DROP PROCEDURE IF EXISTS p //

CREATE PROCEDURE p (IN player TEXT, OUT num INT)
BEGIN
  SELECT COUNT(*) INTO num FROM `sg_playerstats` WHERE `player` = player; 
END

//

DELIMITER ;

Num gets filled correctly, but whatever I put in player, the result is ALWAYS 66. (The table has 66 rows!)

What am I doing wrong???


回答1:


rename your parameter,

CREATE PROCEDURE p (IN _player TEXT, OUT num INT)
BEGIN
  SELECT COUNT(*) INTO num FROM `sg_playerstats` WHERE `player` = _player; 
END

the reason why you are getting that is because it happens to have name collision.



来源:https://stackoverflow.com/questions/14515125/mysql-where-condition-in-procedure-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!