- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 implement END IF statement in a MySQL Stored Procedure?
The following is the syntax of END IF statement in MySQL
IF yourCondition THEN yourStatement ELSE yourStatement END IF
Here is the demo of END IF statement while creating a stored procedure
mysql> DELIMITER // mysql> CREATE PROCEDURE Sp_Test( IN value INT ) - > BEGIN - > IF value < 10 THEN - > select 'Your value is less than 10'; - > ELSE - > select 'Your value is greater than 10'; - > END IF; - > - > END // Query OK, 0 rows affected (1.47 sec) mysql> DELIMITER ;
Call the stored procedure with the help of CALL command.
The syntax is as follows
Now you can call the above stored procedure as shown below
mysql> CALL Sp_Test(15);
The following is the output
+-------------------------------+ | Your value is greater than 10 | +-------------------------------+ | Your value is greater than 10 | +-------------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)
- How to correctly implement conditions in MySQL stored procedure?
- Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors
- How to correctly use DELIMITER in a MySQL stored procedure?
- Implement If else in stored procedure in MySQL?
- How MySQL IF statement can be used in a stored procedure?
- How MySQL IF ELSE statement can be used in a stored procedure?
- How to correctly use delimiter in a MySQL stored procedure and insert values?
- How can MySQL IF ELSEIF ELSE statement be used in a stored procedure?
- Implement Conditional MySQL Query in a stored procedure?
- How to call a stored procedure using select statement in MySQL?
- Implement DELETE query in MySQL stored procedure
- Display records from MySQL stored Procedure with IF…THEN…END IF statements
- How Can MySQL LOOP statement be used in a stored procedure?
- How Can MySQL CASE statement be used in stored procedure?
- Implement Dynamic SQL query inside a MySQL stored procedure?