Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors


Such errors arise when you avoid using the DELIMITER concept. Let us see an example and run a query for stored procedure −

mysql> DELIMITER //
mysql> CREATE PROCEDURE correct_procedure()
   BEGIN
   SELECT 'Hello MySQL !!!';
   END
//
Query OK, 0 rows affected (0.12 sec)
mysql> DELIMITER ;

Following is the syntax to call the stored procedure −

call yourStoredProcedureName();

Call the stored procedure using CALL command −

mysql> call correct_procedure();

This will produce the following output −

+-----------------+
| Hello MySQL !!! |
+-----------------+
| Hello MySQL !!! |
+-----------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.02 sec)

Updated on: 09-Oct-2019

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements