MySQL procedure to display a “select” statement twice

MySQLMySQLi Database

To understand, let us create a stored procedure. Here, we have 2 select statements in the stored procedure −

mysql> DELIMITER //
mysql> CREATE PROCEDURE select_statement()
   -> BEGIN
   ->    SELECT "HI" AS `FIRST VALUE`;
   ->    SELECT "HELLO" AS `SECOND VALUE`;
   -> END
   -> //
Query OK, 0 rows affected (0.09 sec)
mysql> DELIMITER ;

Call the stored procedure using CALL command −

mysql> CALL select_statement();

This will produce the following output −

+-------------+
| FIRST VALUE |
+-------------+
| HI          |
+-------------+
1 row in set (0.00 sec)
+--------------+
| SECOND VALUE |
+--------------+
| HELLO        |
+--------------+
1 row in set (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
raja
Published on 12-Dec-2019 10:39:37
Advertisements