Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to display message from a stored procedure?
To display message from stored procedure on the basis of conditions, let us use IF-ELSE condition −
mysql> DELIMITER //
mysql> CREATE PROCEDURE showMessage(value int,Name varchar(20))
BEGIN
IF(value > 100) then
SELECT CONCAT("HELLO"," ",Name);
ELSE
SELECT CONCAT("BYE"," ",Name);
END IF;
END
//
Query OK, 0 rows affected (0.18 sec)
mysql> DELIMITER ;
Case 1 − Call the stored procedure using CALL command, when value is more than 100 −
call showMessage(200,'John');
This will produce the following output −
+--------------------------+
| CONCAT("HELLO"," ",Name) |
+--------------------------+
| HELLO John |
+--------------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.02 sec)
Case 2 − When the value is less than 100, a difference message will be visible since ELSE condition will execute −
mysql> call showMessage(10,'John');
This will produce the following output −
+------------------------+
| CONCAT("BYE"," ",Name) |
+------------------------+
| BYE John |
+------------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec) Advertisements
