create type ot is object (
employee_id integer,
last_name varchar2(100),
department_id integer,
salary number)
Type created.
create type nt is table of ot
Type created.
declare
emps nt;
begin
select ot (employee_id, last_name, department_id, salary)
bulk collect into emps
from hr.employees;
for rec in (
select d.department_name, sum (e.salary) total_salary
from hr.departments d, table (emps) e
where d.department_id = e.department_id
group by d.department_name)
loop
dbms_output.put_line (rec.department_name || ' - ' || rec.total_salary);
end loop;
end;
Administration - 4400
Accounting - 20308
Purchasing - 24900
Human Resources - 6500
IT - 28800
Public Relations - 10000
Executive - 58000
Shipping - 156400
Sales - 304500
Finance - 51608
Marketing - 19000