IF statement in MySQL stored procedures

MySQL CASE

If statement allows you to execute a set of SQL statements based on condition. If certain condition returns true then statement executes, otherwise not.

Example:

DELIMITER $$
CREATE PROCEDURE MyifCond()
BEGIN
DECLARE x  INT;
SET x = 1;
SET y = 1;
WHILE x  <= 10 DO
SET  x = x + 1;
IF x > 5 THEN
SET  y = y + 1;
END IF;
END WHILE;
SELECT y;
END$$
DELIMITER;

For any types of queries, you can contact us on info@namasteui.com.

You may like:  Filter Rows Using WHERE Statement

Leave a Reply

Your email address will not be published. Required fields are marked *