Categories: MySQL

IF statement in MySQL stored procedures

Share

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;

Recent Posts

India General Elections 2024: A Historic Event

The 2024 Indian General Elections are taking place now, with every individual in the country…

10 hours ago

Unveiling the Ultimate Car Cleaning Kit: Your Road to a Pristine Ride

Introduction: In order to stay clean, car care all in the world is not only…

16 hours ago

Oppo vs Vivo: The Race to be the Number One Smartphone in India

Oppo and Vivo are two smartphone makers in India that manufacture quality mobile phones at…

1 day ago

10 Reasons Why Technology is Good for Education

Educational technology has been very helpful in the era of ever-advancing technology. It opens millions…

2 days ago

Chat GPT Login: Step-by-Step Guide for Beginners

Have you ever thought of a world where asking the Internet for information feels like…

2 days ago

The Sharp-Looking Guy: 5 Essential Tips for Men to Become Sharp

We've gotten so used to seeing men streetwear joggers, ripped jeans, and sleeveless shirts. Hair…

3 days ago