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, eg
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 making my statement invalidate?
Update, parentId is passed in as a parameter, eg
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.