If I create this stored procedure below and the run it I get back both rows from the table when it should be just one query.
CREATE PROCEDURE `getUserName`(IN Guid VARCHAR(36), IN GameID INT(11))
BEGIN
SELECT `Name` as UserName, `GUID` as guid
FROM playerdata
WHERE `GUID` = Guid AND `GameID` = GameID;
END
CALL getUserName('86fd1007-4a9c-11e7-b2e2-1803733c2d41', 1001);
Returns See Image
However if I just run it as a regular query
SELECT `Name` as UserName, `GUID` as guid
FROM playerdata
WHERE `GUID` = "86fd1007-4a9c-11e7-b2e2-1803733c2d41" AND `GameID` = 1001;
Returns See Image
I am baffled as to the behavior considering... at least to me they are the same thing.
答案 0 :(得分:1)
CREATE PROCEDURE `getUserName`(IN IN_Guid VARCHAR(36), IN IN_GameID INT(11))
BEGIN
SELECT `Name` as UserName, `GUID` as guid
FROM playerdata
WHERE `GUID` = IN_Guid AND `GameID` = IN_GameID ;
END
CALL getUserName('86fd1007-4a9c-11e7-b2e2-1803733c2d41', 1001);
尝试以上代码。
如果输入参数与列名具有相同的名称,它最终将评估等效于1=1
,因此没有条件含义。均GameID = GameID
和1=1
都是等价的。
因此,请始终尝试使输入和输出参数名称与特定表的列名不同。
我试过它工作正常。
希望这会对你有所帮助。