- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to correctly use DELIMITER in a MySQL stored procedure?
The correct way is as follows −
DELIMITER // CREATE PROCEDURE yourStoredProcedureName() BEGIN IF yourCondition then yourStatement1 ; else yourStatement2 ; END IF ; END // DELIMITER ;
Let us now see an example and create a stored procedure −
mysql> DELIMITER // mysql> CREATE PROCEDURE delimiter_demo() -> BEGIN -> IF 1 THEN -> SELECT "If condition will always true"; -> else -> select "No" ; -> END IF ; -> END -> // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;
Now you can call the stored procedure using CALL command
mysql> call delimiter_demo();
This will produce the following output −
+-------------------------------+ | If condition will always true | +-------------------------------+ | If condition will always true | +-------------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec)
Advertisements