sql query - Copy - Copy (3)
sql query - Copy - Copy (3)
v_total_employees_terminated NUMBER := 0;
v_total_salary_terminated NUMBER := 0;
BEGIN
-- Display Active employee details
DBMS_OUTPUT.PUT_LINE('Details of Active employees');
DBMS_OUTPUT.PUT_LINE('-----------------------------------');
DBMS_OUTPUT.PUT_LINE('Department_id Total_employees Total_salary');
END;
/
----------------------------------------------------------------
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;
----------------------------------
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;
===================
DECLARE
-- Variables to store total salary and total employees
v_total_employees_active NUMBER := 0;
v_total_salary_active NUMBER := 0;
v_total_employees_terminated NUMBER := 0;
v_total_salary_terminated NUMBER := 0;
BEGIN
-- Display Active employee details
DBMS_OUTPUT.PUT_LINE('Details of Active employees');
DBMS_OUTPUT.PUT_LINE('-----------------------------------');
DBMS_OUTPUT.PUT_LINE('Department_id Total_employees Total_salary');
END;
/