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
|
Declare
Cursor crs Is Select location_id, street_address, postal_code, city,
Cursor(Select department_name, manager_id,
Cursor (Select e.first_name, e.last_name, e.salary
From hr.employees e
Where e.department_id = d.department_id
)
From hr.departments d
Where d.location_id = l.location_id)
From hr.locations l;
--
l_location_id hr.locations.location_id%Type;
l_street_address hr.locations.street_address%Type;
l_postal_code hr.locations.postal_code%Type;
l_city hr.locations.city%Type;
rcrs_dept sys_refcursor;
--
l_department_name hr.departments.department_name%Type;
l_manager_id hr.departments.manager_id%Type;
rcrs_emp sys_refcursor;
--
l_first_name hr.employees.first_name%Type;
l_last_name hr.employees.last_name%Type;
l_salary hr.employees.salary%Type;
Begin
Open crs;
Loop
Fetch crs Into l_location_id, l_street_address, l_postal_code, l_city, rcrs_dept;
Exit When crs%NOTFOUND;
Dbms_Output.put_line('Location :'||l_location_id);
Loop
Fetch rcrs_dept Into l_department_name, l_manager_id, rcrs_emp;
Exit When rcrs_dept%NOTFOUND;
Dbms_Output.put_line(' Department :'||l_department_name);
Loop
Fetch rcrs_emp Into l_first_name, l_last_name, l_salary;
Exit When rcrs_emp%NOTFOUND;
Dbms_Output.put_line(' Employee :'||l_first_name);
End Loop;
End Loop;
End Loop;
Close crs;
End; |
Partager