
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to correctly use delimiter in a MySQL stored procedure and insert values?
- Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors
- Create a stored procedure with delimiter in MySQL
- How to correctly implement conditions in MySQL stored procedure?
- How to correctly implement END IF statement in a MySQL Stored Procedure?
- How to use FOR LOOP in MySQL Stored Procedure?
- How to use IF in stored procedure and select in MySQL?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- Use IN() to get only a particular record in a MySQL stored procedure?
- How to loop thrugh a stored procedure in MySQL?
- How to suppress MySQL stored procedure output?
- How to check whether a stored procedure exist in MySQL?
- MySQL Stored Procedure to create a table?
- How to use % wildcard correctly in MySQL?
- How can we alter a MySQL stored procedure?

Advertisements