简体   繁体   中英

pass one stored procedure result into other stored procedure as parameter in Mysql

I have two function called in stored procedure:

CALL createPost(IN value,@Outvalue);

Now I want to pass '@Outvalue' to other stored procedure:

CALL createPostMedia(@Outvalue);
  • value is retrieved when we run SELECT @Outvalue; But @Outvalue value is not pass to createPostMedia() in parameters

I created a small test that can be useful:

DELIMITER //

CREATE PROCEDURE `createPost`(
    IN `_value` VARCHAR(50),
    OUT `_out_post_id` BIGINT UNSIGNED
)
BEGIN
  INSERT INTO `post` (`value`) VALUES (`_value`);

  SET `_out_post_id` := LAST_INSERT_ID();
END//

CREATE PROCEDURE `createPostMedia`(
    IN `_in_post_id` BIGINT UNSIGNED
)
BEGIN
  INSERT INTO `postmedia` (`post_id`) VALUES (`_in_post_id`);
END//

CREATE PROCEDURE `sp_test`()
BEGIN
  CALL `createPost`('post_one', @`_out_post_id`);
  CALL `createPostMedia`(@`_out_post_id`);
END//

CALL `sp_test`//

DELIMITER ;

SQL Fiddle demo

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.

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