forked from srikanthpragada/plsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobs_summary.sql
More file actions
49 lines (41 loc) · 1.41 KB
/
jobs_summary.sql
File metadata and controls
49 lines (41 loc) · 1.41 KB
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
set serveroutput on
declare
cursor jobcur is
select job_id, job_title
from jobs
where job_id in
(select job_id from employees);
v_count number(3);
v_count_hist number(3);
v_avg_exp number(2);
v_avg_sal employees.salary%type;
v_max_sal employees.salary%type;
v_names varchar(100);
cursor empnames(jobid varchar, maxsal number) is
select first_name
from employees
where job_id = jobid and salary = maxsal;
begin
for jobrec in jobcur
loop
select avg(salary), count(*), max(salary),
avg(floor(months_between(sysdate,hire_date)/12))
into v_avg_sal, v_count, v_max_sal, v_avg_exp
from employees
where job_id = jobrec.job_id;
select count(*) into v_count_hist
from job_history
where job_id = jobrec.job_id;
v_names := '';
for namerec in empnames(jobrec.job_id, v_max_sal)
loop
v_names := v_names || namerec.first_name || ',';
end loop;
dbms_output.put_line('Job Title : ' || jobrec.job_title);
dbms_output.put_line('No. Employees : ' || v_count);
dbms_output.put_line('Avg Salary : ' || v_avg_sal);
dbms_output.put_line('Avg Exp : ' || v_avg_exp);
dbms_output.put_line('History Count : ' || v_count_hist);
dbms_output.put_line('Top Employee(s) : ' || rtrim(v_names,','));
end loop;
end;