-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepEmpSalary4Dept.sql
98 lines (72 loc) · 2.76 KB
/
RepEmpSalary4Dept.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- ***********************************************************************
-- *
-- * Program : RepEmployee4Dept.sql
-- * Purpose : Report to show Total salary of Employees for a Department
-- *
-- * Parameters : Department - Department Id. IF nothing entered then
-- * show all the employees
-- * Remarks : Run the report in the SQLPLUS prompt by running the following command:
-- * @RepEmpSalary4Dept
-- ***********************************************************************
REM Whenever there is a sql error, rollback and then exit
REM -----------------------------------------------------
REM
WHENEVER sqlerror exit
CLEAR COLUMNS
CLEAR COMPUTES
CLEAR BREAKS
set feedback off
set echo off
set verify off
set heading on
set define ON
TTITLE LEFT 'Date: 16/04/2024' RIGHT 'PAGE: ' FORMAT 999 SQL.PNO SKIP 2 -
CENTER 'Employee Details Report for Department(s) Report' SKIP 2
PROMPT
PROMPT
Prompt 'Enter a Valid Department Id. None/Null for all'
PROMPT '----------------------------------------------'
PROMPT
PROMPT
-- Accept the department id
Input
Accept department prompt 'Department Id:'
VARIABLE l_dept NUMBER ;
EXEC :l_dept := '&department'
BTITLE CENTER 'END OF THE REPORT' SKIP 2
Break on department
COMPUTE SUM OF SALARY ON DEPARTMENT
Column Department for a30
Column EmpName for a30
Column JobTitle for a20
Column Mgrname for a20
Column HiredDate for a12
Column EmpId for 99999
Break on department SKIP 1
set pages 30
SET newpage 0
set LINESIZE 150
-- Send the output of the query to EmpDeptReport.Lst in the current directory.
SPOOL RepEmpSalary4Dept
-- Query for fetching all the employees
SELECT
dep.department_name department,
emp.employee_id empid,
emp.employee_name empname,
emp.job_title jobtitle,
TO_DATE(emp.date_hired, 'DD-MON-YYYY') hireddate,
emp.salary,
mgr.employee_name mgrname
FROM
employees emp
JOIN departments dep ON emp.department_id = dep.department_id
LEFT JOIN employees mgr ON mgr.employee_id = emp.manager_id
WHERE
dep.department_id LIKE '%&department%'
ORDER BY
dep.department_id,
emp.employee_id;
SPOOL OFF
set feedback off
set echo off
set verify off