简体   繁体   English

Mysql存储过程中的不同结果

[英]Different Result in Mysql Stored Procedure

I have a stored procedure named getvotes(postitem varchar(50),userid varchar(50)) that gets the number of votes given by a user for certain item. 我有一个名为getvotes(postitem varchar(50),userid varchar(50))的存储过程getvotes(postitem varchar(50),userid varchar(50))该过程获取用户为特定项目提供的投票数。 The DML statement inside this procedure is 该过程中的DML语句是

select count(*) from tblvotes where `postitem`=postitem and `userid`=userid;

it gives me the result of 30. But when I run the sql(outside the stored procedure with the same argument values) using 它给我30的结果。但是当我运行sql(使用相同参数值的存储过程之外)时,使用

select count(*) from tblvotes where `postitem`=md5(1) and `userid`=md5(1);

the result is 10. 结果是10。

Whats wrong with my query? 我的查询出了什么问题?

Thanks! 谢谢!

Don't use parameter names that have the same name as column names or whatever. 不要使用与列名同名的参数名。

I usually prefix every parameter with p_ and every variable with v_ to avoid such errors. 我通常在每个参数前加上p_前缀,在每个变量前加上v_前缀,以避免出现此类错误。

Check the length of the encryption used for MD5 and User HEX if the hash comparison may fail 如果哈希比较可能失败,请检查用于MD5和用户十六进制的加密长度

select count(*) from tblvotes where postitem = HEX(MD5(1) and userid = HEX(MD5(1)); select count(*) from tblvotes where postitem = HEX(MD5(1) and userid = HEX(MD5(1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM