Chapter 13 How to create Store Procedures and Functions Lab 1
Chapter 13 How to create Store Procedures and Functions Lab 1
DATABASE II
Chapter 13
How to create stored procedures and functions (Lab)
DELIMITER //
CREATE PROCEDURE test()
BEGIN
SELECT 'This is a test.' AS message;
END//
CALL test();
USE ap;
CALL test();
SET percent_difference =
(max_invoice_total - min_invoice_total) /
min_invoice_total * 100;
SELECT MIN(invoice_due_date)
INTO first_invoice_due_date
FROM invoices
WHERE invoice_total - payment_total - credit_total > 0;
CASE terms_id_var
WHEN 1 THEN
SELECT 'Net due 10 days' AS Terms;
WHEN 2 THEN
SELECT 'Net due 20 days' AS Terms;
WHEN 3 THEN
SELECT 'Net due 30 days' AS Terms;
ELSE
SELECT 'Net due more than 30 days' AS Terms;
END CASE;
END//
DELIMITER //
WHILE i < 4 DO
SET s = CONCAT(s, 'i=', i, ' | ');
SET i = i + 1;
END WHILE;
SELECT s AS message;
END//
DELIMITER //
OPEN invoices_cursor;
CLOSE invoices_cursor;