-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXPLICIT_CURSOR_FOR_LOOP.sql
More file actions
37 lines (32 loc) · 1023 Bytes
/
EXPLICIT_CURSOR_FOR_LOOP.sql
File metadata and controls
37 lines (32 loc) · 1023 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
-- please login into hr user
/* Simple Explicit cursors using for loop gives all the employee id and FirstName */
DECLARE
CURSOR c1 IS SELECT e.employee_id,e.first_name FROM employees e
ORDER BY e.employee_id;
v_emp_id NUMBER(10);
v_f_name VARCHAR2(20);
BEGIN
FOR i IN c1
LOOP
dbms_output.put_line('Employee ID is >> '||i.employee_id);
dbms_output.put_line('Employee Name is >> '||i.first_name);
dbms_output.put_line('***********************************');
END LOOP;
END;
-- Cursor using simple loop
DECLARE
CURSOR c1 IS SELECT e.employee_id,e.first_name FROM employees e
ORDER BY e.employee_id;
v_emp_id NUMBER(10);
v_enp_name VARCHAR2(20);
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO v_emp_id,v_enp_name;
dbms_output.put_line('Employee ID is >> '||v_emp_id);
dbms_output.put_line('Employee Name is >> '||v_enp_name);
dbms_output.put_line('***********************************');
EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;
END;