-
Notifications
You must be signed in to change notification settings - Fork 0
/
17dbms
49 lines (39 loc) · 1.35 KB
/
17dbms
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
38
39
40
41
42
43
44
45
46
47
48
49
EXPERIMENT 17
PL/SQL PROGRAMS – CURSOR
______________________________ Q1 ____________________________________________________
Write a PL/SQL program to create a name list of customers using CURSOR
mysql> DELIMITER $$
mysql> CREATE PROCEDURE list_name (INOUT name_list varchar(4000))
->
-> BEGIN
-> DECLARE is_done INTEGER DEFAULT 0;
-> DECLARE s_name varchar(100) DEFAULT "";
-> DECLARE stud_cursor CURSOR FOR
-> SELECT name FROM customer;
-> DECLARE CONTINUE HANDLER FOR NOT FOUND SET is_done = 1;
-> OPEN stud_cursor;
-> get_list: LOOP
-> FETCH stud_cursor INTO s_name;
-> IF is_done = 1 THEN
-> LEAVE get_list;
-> END IF;
-> SET name_list = CONCAT(s_name, ";",name_list);
-> END LOOP get_list;
-> CLOSE stud_cursor;
-> END$$
Query OK, 0 rows affected (0.06 sec)
mysql> SET @name_list ="";//
-> $$
Query OK, 0 rows affected (0.00 sec)
mysql> SET @name_list ="";$$
Query OK, 0 rows affected (0.00 sec)
mysql> call list_name(@name_list)$$
Query OK, 0 rows affected (0.03 sec)
mysql> select @name_list;$$
+----------------------------------------------+
| @name_list |
+----------------------------------------------+
| RAVI;APU;DYAN;aaaa;APPU;ARNN;ANNT;JOHN;APPU; |
+----------------------------------------------+
1 row in set (0.00 sec)
//VERIFIED