MySQL Stored Procedure calling with INT and VARCHAR values

Database

To call a stored procedure, you can use CALL command. Following is the syntax −

CALL yourStoredProcedureName(parameter if any);

Let us first create a sample procedure. Following is the query to create a stored procedure. Here, we have set two values, one is an INT and another VARCHAR −

mysql> DELIMITER //
mysql> CREATE PROCEDURE CALL_PROC(Id int,Name varchar(40))
   BEGIN
   SELECT CONCAT('You have entered the Id which is=',Id);
   SELECT CONCAT('You have entered the Name which is=',Name);
   END
//
Query OK, 0 rows affected (0.21 sec)
mysql> DELIMITER ;

Following is the query to call a stored procedure in MySQL −

mysql> CALL CALL_PROC(1001,'Chris');

This will produce the following output −

+------------------------------------------------+
| CONCAT('You have entered the Id which is=',Id) |
+------------------------------------------------+
| You have entered the Id which is=1001          |
+------------------------------------------------+
1 row in set (0.00 sec)
+----------------------------------------------------+
| CONCAT('You have entered the Name which is=',Name) |
+----------------------------------------------------+
| You have entered the Name which is=Chris           |
+----------------------------------------------------+
1 row in set (0.02 sec)
Query OK, 0 rows affected, 1 warning (0.04 sec)
raja
Published on 04-Oct-2019 11:04:48
Advertisements