DELIMITER $$
DROP PROCEDURE IF EXISTS HelloWorld$$
CREATE PROCEDURE HelloWorld ()
BEGIN
SELECT 'Hello World';
END$$
DELIMITER;
CALL HelloWorld();
DELIMITER $$
DROP PROCEDURE IF EXISTS Variable$$
CREATE PROCEDURE Variable (input_number INT)
BEGIN
DECLARE my_int INT;
SET my_int =SQRT(input_number);
select my_int;
END$$
DELIMITER ;
CALL Variable(100);
DELIMITER $$
DROP PROCEDURE IF EXISTS discounted$$
CREATE PROCEDURE discounted (IN price NUMERIC(8,2), OUT discountPrice NUMERIC(8,2))
BEGIN
IF (price >= 500.0) THEN
SET discountPrice = price * 0.8;
ELSEIF(price >= 100) THEN
SET discountPrice = price * 0.9;
ELSE
SET discountPrice = price;
END IF;
END$$
DELIMITER ;
CALL discounted(500,@newPrice);
SELECT @newPrice;
LOOP END LOOP
, WHILE END WHILE
, REPEAT UNTIL
DELIMITER $$
DROP PROCEDURE IF EXISTS simple_loop$$
CREATE PROCEDURE simple_loop ()
BEGIN
DECLARE counter INT DEFAULT 0;
my_loop : LOOP
SET counter = counter + 1;
IF counter = 10 THEN
LEAVE my_loop;
END IF;
END LOOP my_loop;
SELECT "I can count to 10.";
END$$
DELIMITER ;
CALL simple_loop();