Tutorialspoint

How to select return value from MySQL prepared statement?


1 Answer
Rama Giri

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)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.