-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.1 cursors.sql
56 lines (51 loc) · 1.64 KB
/
8.1 cursors.sql
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
50
51
52
53
54
55
56
DECLARE
-- Without record
CURSOR c_emps IS
SELECT
first_name,
last_name
--department_name
FROM
employees;
--JOIN departments USING ( department_id )
--WHERE
--department_id BETWEEN 30 AND 60;
v_first_name employees.first_name%TYPE;
v_last_name employees.last_name%TYPE;
v_departement_name departments.department_name%TYPE;
-- With defined record
TYPE r_emp IS RECORD (
first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE
--departement_name departments.department_name%TYPE
);
v_emp r_emp;
-- With rowtype
v_emp1 c_emps%rowtype; -- recommended
BEGIN
OPEN c_emps;
FETCH c_emps INTO
v_first_name,
v_last_name;
--,v_departement_name;
dbms_output.put_line(v_first_name
|| ', '
|| v_last_name
--|| ' in departement : '
--|| v_departement_name
|| chr(10));
FETCH c_emps INTO v_emp;
dbms_output.put_line(v_emp.first_name
|| ', '
|| v_emp.last_name
--|| ' in departement : '
--|| v_emp.departement_name
|| chr(10));
-- with rowtype
FETCH c_emps INTO v_emp1;
dbms_output.put_line(v_emp1.first_name
|| ', '
|| v_emp1.last_name
|| chr(10));
CLOSE c_emps;
END;