
- 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
Implement If else in stored procedure in MySQL?
To implement if-else, the syntax is as follows −
if yourCondition then yourStatement1; else yourStatement2; end if ;
To understand the above concept for if-else in a stored procedure, let us create a stored procedure −
mysql> delimiter // mysql> create procedure If_else_stored_demo(value int) begin if value > 1000 then select "your value is greater than 1000"; else select "your value is less than or equal to 1000"; end if ; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
Now you can call the stored procedure using call command −
mysql> call If_else_stored_demo(500);
This will produce the following output −
+------------------------------------------+ | your value is less than or equal to 1000 | +------------------------------------------+ | your value is less than or equal to 1000 | +------------------------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
- Related Articles
- How MySQL IF ELSE statement can be used in a stored procedure?
- Implement DELETE query in MySQL stored procedure
- How can MySQL IF ELSEIF ELSE statement be used in a stored procedure?
- Implement Conditional MySQL Query in a stored procedure?
- How to correctly implement END IF statement in a MySQL Stored Procedure?
- How to correctly implement conditions in MySQL stored procedure?
- Implement Dynamic SQL query inside a MySQL stored procedure?
- How to use IF in stored procedure and select in MySQL?
- How MySQL IF statement can be used in a stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- MySQL Sum Query with IF Condition using Stored Procedure
- View stored procedure/function definition in MySQL?
- Set conditions in a MySQL stored procedure
- MySQL stored procedure return value?
- MySQL stored-procedure: out parameter?

Advertisements