How to select return value from MySQL prepared statement?


Let us create a stored procedure and select return value from MySQL prepared statement −

mysql> DELIMITER //
mysql> CREATE PROCEDURE return_value()
   -> BEGIN
   ->   SET @returnQuery= 'SELECT 98 INTO @value';
   ->   PREPARE stmt FROM @returnQuery;
   ->   EXECUTE stmt;
   -> END
   -> //
Query OK, 0 rows affected (0.20 sec)

mysql> DELIMITER ;

Call stored procedure using CALL command.

mysql> call return_value();
Query OK, 1 row affected (0.07 sec)

Display value using select statement −

mysql> select @value;

This will produce the following output −

+--------+
| @value |
+--------+
|     98 |
+--------+
1 row in set (0.00 sec)
raja
Published on 11-Jul-2019 15:34:25
Advertisements