
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Correctly Implement END IF Statement in 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
CALL yourStoredProcedureName();
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)
Advertisements