
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 Conditions in MySQL Stored Procedure
To set conditions in stored procedure, use the below syntax −
if yourCondition then yourStatement1; else yourStatement2'; end if ; end //
Let us implement the above syntax in order to correct missing semicolon in stored procedure −
mysql> delimiter // mysql> create procedure Test_Demo(In inputValue int) -> BEGIN -> if inputValue=10 then -> select 'You have won 100$'; -> else -> select 'Sorry !!!'; -> end if ; -> end -> // Query OK, 0 rows affected (0.20 sec) mysql> delimiter ;
Now you can call stored procedure using CALL command −
mysql> call Test_Demo(10);
This will produce the following output −
+-------------------+ | You have won 100$ | +-------------------+ | You have won 100$ | +-------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)
Advertisements