- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 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)
- Related Articles
- How to correctly implement END IF statement in a MySQL Stored Procedure?
- How to correctly use DELIMITER in a MySQL stored procedure?
- Set conditions in a MySQL stored procedure
- Implement DELETE query in MySQL stored procedure
- How to correctly use delimiter in a MySQL stored procedure and insert values?
- Implement If else in stored procedure in MySQL?
- Implement Conditional MySQL Query in a stored procedure?
- Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors
- Implement Dynamic SQL query inside a MySQL stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- How to suppress MySQL stored procedure output?
- How to use FOR LOOP in MySQL Stored Procedure?
- How to loop thrugh a stored procedure in MySQL?
- How to quit/ exit from MySQL stored procedure?
- How can we invoke MySQL stored procedure?

Advertisements