1- employee under terminated manager
SET NULL "NULL";
SET FEEDBACK OFF;
SET ECHO OFF;
SET HEADING OFF;
SET WRAP OFF;
SET LINESIZE 10000;
SET TAB OFF;
SET PAGES 0;
SET DEFINE OFF;
set serveroutput on;
declare
act number;
ter number;
mgrname varchar2(200);
mgr_sup varchar2(200);
superv varchar2(200);
cursor curr is
select emp_id,
concat(emp_fname,concat(' ',emp_lname)) as empname,
emp_status
from emp;
cursor curr2 is
select superv,
concat(e.emp_fname,concat(' ',e.emp_lname)) as mgrname,
e.emp_status as stat,
e.mgr_id as mgr1
from emp e,
emp a
where a.mgr_id=e.emp_id;
c1 curr%rowtype;
c2 curr2%rowtype;
begin
select count(emp_id) into act from emp where emp_status='Active';
select count(emp_id) into ter from emp where emp_status='Terminated';
dbms_output.put_line('**Status Count**');
dbms_output.put_line('Active '||' '||act);
dbms_output.put_line('Terminated '||' '||ter);
dbms_output.put_line('**Employees under Terminated Manager**');
dbms_output.put_line('emp_id emp_name Mgr_name Mgr_Status Mgr_Supervisor');
open curr;
open curr2;
loop
fetch curr into c1;
fetch curr2 into c2;
exit when curr%notfound;
if c2.stat='Terminated' and c1.emp_status='Active' then
select concat(emp_fname,concat(' ',emp_lname)) into superv from emp where
emp_id=c2.mgr1;
dbms_output.put_line(c1.emp_id||' '||c1.empname||' '||c2.mgrname||' '||
c2.stat||' '||superv);
end if;
end loop;
end;
/
/*
Enter your query below.
Please append a semicolon ";" at the end of the query
*/
exit;
This study source was downloaded by 100000889764202 from CourseHero.com on 08-23-2024 00:19:43 GMT -05:00
https://www.coursehero.com/file/92245530/plsql-e2-62136txt/
2- calculating bonus
SET NULL "NULL";
SET FEEDBACK OFF;
SET ECHO OFF;
SET HEADING OFF;
SET WRAP OFF;
SET LINESIZE 10000;
SET TAB OFF;
SET PAGES 0;
SET DEFINE OFF;
set serveroutput on;
declare
incentive number;
work_exp number;
cursor curr is
select emp_id,
concat(emp_fname,concat(' ',emp_lname)) as empname,
emp_hiredate
from emp
where emp_status='Active'
and extract(month from to_date(emp_hiredate, 'yyyy-mm-dd'))=12;
c curr%rowtype;
begin
open curr;
dbms_output.put_line('Employees with yearly incentive amounts:');
dbms_output.put_line('**********');
dbms_output.put_line('Employee ID Name of the Employee Hire Date Incentive
Amount');
dbms_output.put_line('**********');
loop
fetch curr into c;
exit when curr%notfound;
work_exp:=MONTHS_BETWEEN(to_date('31/12/2020', 'dd/mm/yyyy'),c.emp_hiredate)/12;
case
when work_exp>13 then incentive:=8000;
when work_exp>11 then incentive:=5000;
when work_exp>9 then incentive:=3000;
when work_exp>7 then incentive:=2000;
when work_exp>4 then incentive:=1000;
when work_exp>0 then incentive:=400;
else incentive:='null';
end case;
dbms_output.put_line(c.emp_id||' '||c.empname||' '||c.emp_hiredate||' '||
incentive);
end loop;
dbms_output.put_line('**********');
dbms_output.put_line('The number of rows fetched is '||curr%rowcount);
dbms_output.put_line('**********');
end;
/
/*
Enter your query below.
Please append a semicolon ";" at the end of the query
*/
exit;
3- employees not assigned to any dept.
SET NULL "NULL";
SET FEEDBACK OFF;
This study source was downloaded by 100000889764202 from CourseHero.com on 08-23-2024 00:19:43 GMT -05:00
https://www.coursehero.com/file/92245530/plsql-e2-62136txt/
SET ECHO OFF;
SET HEADING OFF;
SET WRAP OFF;
SET LINESIZE 10000;
SET TAB OFF;
SET PAGES 0;
SET DEFINE OFF;
set serveroutput on;
update emp set dept_id=(select dept_id from dept minus select dept_id from emp)
where dept_id is null;
update emp set mgr_id=7 where dept_id=10;
alter table emp add mgr_name varchar(50);
update emp set mgr_name=(select concat(emp_fname,concat(' ',emp_lname)) from emp
e where emp.mgr_id = e.emp_id);
declare
emp_id number;
emp_fname varchar(50);
emp_lname varchar(50);
emp_status varchar(50);
dept_name varchar(50);
mgr_name varchar(50);
cursor cur is
select e.emp_id,
e.emp_fname,
e.emp_lname,
e.emp_status,
d.dept_name,
e.mgr_name
from emp e,
dept d
where e.dept_id =10
and e.dept_id=d.dept_id;
begin
open cur;
dbms_output.put_line('emp_Id emp_fname emp_Lname emp_Status Dept_name
Mgr_name');
loop
fetch cur into emp_id, emp_fname, emp_lname, emp_status, dept_name, mgr_name;
exit when cur%notfound;
dbms_output.put_line(emp_id||' '||emp_fname||' '||emp_lname||' '||emp_status||'
'||dept_name||' '||mgr_name);
end loop;
end;
/
/*
Enter your query below.
Please append a semicolon ";" at the end of the query
*/
exit;
4- display Dept head
SET NULL "NULL";
SET FEEDBACK OFF;
SET ECHO OFF;
SET HEADING OFF;
SET WRAP OFF;
SET LINESIZE 10000;
SET TAB OFF;
SET PAGES 0;
SET DEFINE OFF;
This study source was downloaded by 100000889764202 from CourseHero.com on 08-23-2024 00:19:43 GMT -05:00
https://www.coursehero.com/file/92245530/plsql-e2-62136txt/
set serveroutput on;
select 'emp_id emp_fname emp_Lname emp_HireDate emp_Status Dept_name Mgr_name'
from dual;
select A.emp_id,
A.emp_fname,
A.emp_lname,
A.emp_hireDate,
A.emp_status,
d.Dept_name,
case
when A.Mgr_id is not null and B.emp_status = 'Active' then
concat(concat(B.emp_fname, ' '), B.emp_lname)
when A.Mgr_id is not null and B.emp_status = 'Terminated' then
'Terminated Manager'
when A.Mgr_id is null and C.emp_status = 'Active' then
concat(concat(C.emp_fname, ' '), C.emp_lname)
when A.Mgr_id is null or D.dept_head is not null or
C.emp_status = 'Terminated' then
'Terminated Manager'
end mgr_name
from emp A, dept D, emp B, emp C
where A.emp_status = 'Active'
and to_date(A.emp_hireDate, 'dd/mm/yyyy') >=
to_date('01/01/2000', 'dd/mm/yyyy')
and A.dept_id = d.dept_id (+)
and A.mgr_id = B.emp_id (+)
and C.emp_id (+)= D.dept_head
order by 1
/
exit;
This study source was downloaded by 100000889764202 from CourseHero.com on 08-23-2024 00:19:43 GMT -05:00
https://www.coursehero.com/file/92245530/plsql-e2-62136txt/
Powered by TCPDF (www.tcpdf.org)