Mysql - Stored procedure OUT variable return null

后端 未结 2 1629
滥情空心
滥情空心 2021-01-24 20:28

My Table Structure is:

DROP TABLE IF EXISTS `child`;

CREATE TABLE `child` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KE         


        
相关标签:
2条回答
  • 2021-01-24 21:05

    The syntax for setting the variable is incorrect, use : like,

    SET parent_id := LAST_INSERT_ID();
     SET child_id := LAST_INSERT_ID();
    

    or You can do the setting as

    select LAST_INSERT_ID() into parent_id;
    
    0 讨论(0)
  • 2021-01-24 21:29

    You might have already solved this by now, but the first thing I noticed about your stored procedure is that you have a local variable with the same name as the output variable (parent_id). It looks to me that you're setting the value of the local variable rather than the return variable, so the caller never sees the correct value.

    Perhaps removing the local parent_id variable declaration will solve your problem.

    0 讨论(0)
提交回复
热议问题