-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass 23.sql
More file actions
37 lines (28 loc) · 857 Bytes
/
class 23.sql
File metadata and controls
37 lines (28 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
USE sakila;
DELIMITER $$
CREATE PROCEDURE create_payment_id (OUT payment_list TEXT)
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE amount DECIMAL(5,2);
DECLARE email_list TEXT DEFAULT '';
-- Cursor to get payment amounts less than 10
DECLARE cur CURSOR FOR
SELECT amount FROM payment WHERE amount < 10;
-- Handler when cursor reaches the end
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- Open the cursor
OPEN cur;
payment_loop: LOOP
FETCH cur INTO amount;
IF done THEN
LEAVE payment_loop;
END IF;
-- Concatenate amounts
SET email_list = CONCAT(amount, '-', email_list);
END LOOP;
-- Close the cursor
CLOSE cur;
-- Set output
SET payment_list = email_list;
END$$
DELIMITER ;