开发者

Prepared statement returning zero results

I am attempting to execute the following prepared statement:

PREPARE stmt FROM 'SELECT * FROM Inventory I WHERE I.ParentId = ?';
EXECUTE stmt USING @parentId;

DEALLOCATE PREPARE stmt;

When I execute this statement, it returns the column headers with no rows. It should return 6 rows.

If I execute this same statement as a normal SQL statement without the PREPARE and EXECUTE statement, I get results, e.g.

SELECT * FROM Inventory I WHERE I.ParentId = parentId;

Results are returned. What am I doing wrong? Is there some kind of casting going on that is开发者_Go百科 making my statement invalidate?

Update, parentId is passed in as a parameter, e.g.

CREATE DEFINER=`george`@`%` PROCEDURE `ListInventoryByParentId`(IN parentId INT)


User variable @parentId and procedure argument parentID are independent. You need to set your user variable to procedure argument before executing statement.

SET @parentID = parentId;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜