SlideShare a Scribd company logo
1 of 39
CREATE OR REPLACE PACKAGE YM_PKG_PL_TASK
IS
PROCEDURE MIN_MAX_SALARY_DIFFERENCE --PROCEDURE FPR MINIMUMAND MAXIMUM
SALARY DIFFERENCE
(EMP_ID in NUMBER,WEIGHT_COMPANY IN VARCHAR2, WEIGHT_DEPT IN VARCHAR2,
P_SALARY OUT NUMBER ,P_MIN_SALARY OUT NUMBER,P_MAX_SALARY OUT NUMBER; )
PROCEDURE increase_emp_salary_if_task
(p_emp_id number ,p_increase varchar2 , p_value number;)
*/create table time_keeping
(emp_id number ,keeping_date date , transaction_type varchar2(200/*) )
------------------------------------------------------------------------------------
PROCEDURE keeping_time
(p_emp_id number ,p_status varchar2;)
---------------------------------------------
*/CREATE TABLE time_keeping
(emp_id NUMBER ,keeping_date DATE , transaction_type VARCHAR2(200/*))
---------------------------------------------------------------------------------------------------
procedure calc_prmemium_first_level --CALCULATE PREMIUMFIRST LEVEL
(p_value number , p_prm_number number;)
procedure calc_prmemium
(p_value NUMBER , p_prm_number NUMBER,p_deposit_value NUMBER ); --
SECOND_PREM_TASK_level
-----------------------------------------------------------------------------------
*/CREATE TABLE premiums
(item_id number , premium_id number ,premium_amount number,
deposit_amount number ,outstand_amount number/*)
--------------------------------------------------------------------------------------------
PROCEDURE CALC_EMPLOYEE_TAX
(P_EMP_sal NUMBER ); --CALCULATE EMPLOYEE TAX
FUNCTION GET_FULL_NAME
(EMP_ID IN NUMBER ) RETURN VARCHAR2 ; --full name by emp_id
FUNCTION GET_DEPT_NAME_FINAL_TASK
(P_EMP_ID NUMBER ,P_TYPE_E_OR_D departments.department_name%type)
RETURN departments.department_name%type ; --GET DEPARTMENTT NAME
FUNCTION GET_FULL_ADRR_FOR_DEPT_OR_EMP
(DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2;
FUNCTION GET_CITY_FOR_DEPT_OR_EMP
(DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2;
FUNCTION GET_SAL_CATEGORY
(EMP_ID NUMBER ) --SAL_CATEGORY by emp_id
RETURN VARCHAR2;
FUNCTION GET_SAL_CATG
(P_EMP_sal NUMBER ) --sal category by amount
RETURN varchar2;
FUNCTION GET_SINGLE_DETAILS_FOR_EMP
(EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2;
FUNCTION F_MGR_Y_N
(EMP_ID NUMBER , P_TYPE_E_OR_D VARCHAR2 ) --THIS EMPLOYEE ID IS MANAGER OR NOT ? for
emps or dept
RETURN VARCHAR2;
FUNCTION F_COMM_Y_N
(EMP_ID NUMBER ) --THIS EMPLOYEE HAVE COMMISSION OR NOT RETURN (Y OR N)
RETURN VARCHAR2;
FUNCTION MIN_MAX_SALARY_DIFFERENCE
(EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 ) --MIN_MAX_SALARY_DIFFERENCE for emp or
dept
RETURN number;
FUNCTION MIN_MAX_SAL_DIFFR_WITH_SCALE --MIN_MAX_SALary_DIFFRence_with_SCALE (id,'m
or n ','g or d') SCALE (GENERAL OR PER DEPT)
(EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 ,P_SCALE VARCHAR2 )--for emp or dept
RETURN number;
END YM_PKG_PL_TASK;
BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOODDD
DDDDDDDDDDDDDDYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
CREATE OR REPLACE PACKAGE BODY YM_PKG_PL_TASK
IS
PROCEDURE MIN_MAX_SALARY_DIFFERENCE --PROCEDURE FPR MINIMUMAND MAXIMUM
SALARY DIFFERENCE
(EMP_ID in NUMBER,WEIGHT_COMPANY IN VARCHAR2, WEIGHT_DEPT IN VARCHAR2,
P_SALARY OUT NUMBER ,P_MIN_SALARY OUT NUMBER,P_MAX_SALARY OUT NUMBER)
IS
V_JOB_ID employees.job_id%TYPE;
V_SALARY NUMBER;
V_DEPT_ID NUMBER;
V_SUM_SAL NUMBER;
V_SUM_SAL_DEPT NUMBER;
V_PERC_FOR_COM NUMBER;
V_PERC_FOR_DEPT NUMBER;
BEGIN
IF upper(WEIGHT_COMPANY) like 'C'
AND upper(WEIGHT_DEPT) like 'D' then
SELECT salary
INTO P_SALARY
FROM employees
WHERE employee_id=EMP_ID;
SELECT min(salary), max(salary)
INTO P_MIN_SALARY ,P_MAX_SALARY
FROM employees
WHERE job_id=V_JOB_ID;
SELECT job_id
INTO V_JOB_ID
FROM employees
WHERE employee_id=EMP_ID;
SELECT salary
INTO V_SALARY
FROM employees
WHERE employee_id=EMP_ID;
SELECT DEPARTMENT_ID
INTO V_DEPT_ID
FROM employees
WHERE employee_id=EMP_ID;
SELECT SUM(salary)
INTO V_SUM_SAL
FROM employees;
SELECT SUM(salary)
INTO V_SUM_SAL_DEPT
FROM employees
WHERE DEPARTMENT_ID=V_DEPT_ID;
V_PERC_FOR_COM :=SUBSTR( V_SALARY/V_SUM_SAL,0,4; )
V_PERC_FOR_DEPT :=SUBSTR( V_SALARY/V_SUM_SAL_DEPT,2,2; )
DBMS_OUTPUT.PUT_LINE ('SALARY IS :'||' '||P_SALARY ||' '||'MIN SALARY IS:
||' '||'P_MIN_SALARY ||' '||'MAX SALARY IS :'|| P_MAX_SALARY||' '||'FOR '||'(
'||V_JOB_ID||')'||'JOB;)'
DBMS_OUTPUT.PUT_LINE('HIS SALARY REPRESENTS '||' '||V_PERC_FOR_COM||'%'||'FROM
COMPANY SALARIES;)'
DBMS_OUTPUT.PUT_LINE(' AND HIS SALARY REPRESENTS '||' '||V_PERC_FOR_DEPT||'%'||'FROM
HIS DEPT SALARIES;) '
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp id and (C and D;)' )
END IF;
end;
---------------------------------------------------------------------------------------------------------------------------
----
--INCREASE SALARY BY USING IF STATEMENT
PROCEDURE increase_emp_salary_if_task ( p_emp_id number ,p_increase varchar2 , p_value
number)
is
v_dept_sal_avg EMPLOYEES.SALARY%type;
v_sal_avg EMPLOYEES.SALARY%type;
v_sal EMPLOYEES.SALARY%type;
v_value number;
v_dept_id number;
v_emp_name varchar2 (200;)
begin
select department_id into v_dept_id from employees
where employee_id = p_emp_id;
select avg(salary)into v_dept_sal_avg
from employees
where department_id =v_dept_id;
select avg(salary)into v_sal_avg
from employees;
select first_name||' '||last_name
into v_emp_name from employees
where employee_id = p_emp_id;
select salary into v_sal from employees
where employee_id = p_emp_id;
if
upper (p_increase) like 'A' then
select avg(salary)into v_dept_sal_avg
from employees
where department_id =v_dept_id;
if
p_value >v_dept_sal_avg then
DBMS_OUTPUT.PUT_LINE ('these amount larger thane '||my_pkg.get_dept_name(p_emp_id)||'
department salary AVG;)'
else
update employees
set salary=salary+p_value
where employee_id = p_emp_id;
if sql%found then
insert into update_emp_salary_details
(user_id ,increase_date , emp_name_increase ,sal_bef_increase ,sal_aft_increase
,increase_amount,increase_type)
values (user ,sysdate ,v_emp_name,v_sal,v_sal+p_value,p_value,'increased by amount;)'
end if;
DBMS_OUTPUT.PUT_LINE ('salary is increased;)'
end if;
elsif
upper (p_increase)like 'P' then
v_value:=p_value/v_sal;
if
v_value >= .99 then
DBMS_OUTPUT.PUT_LINE ('these amount larger thane current salary;)'
else
if
v_sal+(v_sal*v_value) > v_sal_avg then
DBMS_OUTPUT.PUT_LINE ('salary larger than the'||'
'||''||my_pkg.get_dept_name(p_emp_id)||''||' '||' department salary AVG;)'
else
update employees
set salary=salary+salary*v_value
where employee_id = p_emp_id;
if sql%found then
insert into update_emp_salary_details
(user_id ,increase_date , emp_name_increase ,sal_bef_increase ,sal_aft_increase
,increase_amount,increase_type)
values(user,sysdate ,v_emp_name,v_sal,v_sal+(v_sal*v_value),p_value,'increasedbypercentage;)'
end if;
DBMS_OUTPUT.PUT_LINE ('salary % is increased;)'
end if;
end if;
end if;
end;
-------------------------------------------------------------------------
*/create table time_keeping
(emp_id number ,keeping_date date , transaction_type varchar2(200/*) )
---------------------------------------------------------------------------------------------------------------------------
---------------------
PROCEDURE keeping_time
(p_emp_id number ,p_status varchar2)
is
v_emp_name varchar2(200;)
begin
select first_name||' '||last_name
into v_emp_name from employees
where employee_id = p_emp_id;
if
upper (p_status) like 'I' then
insert into time_keeping
(emp_id ,keeping_date , transaction_type)
values (p_emp_id,to_char (systimestamp,'fmdd/mm/yyyy- hh24:mi:ss'),upper (p_status; ) )
DBMS_OUTPUT.PUT_LINE('The employee'||': '||initcap(v_emp_name)||' '||'is enrolled IN;)'
elsif
upper (p_status) like 'O' then
insert into time_keeping
(emp_id ,keeping_date , transaction_type)
values (p_emp_id,to_char (systimestamp,'fmdd/mm/yyyy- hh24:mi:ss' ),upper (p_status; ) )
DBMS_OUTPUT.PUT_LINE('The employee'||': '||initcap(v_emp_name)||' '||'is enrolled OUT;)'
end if;
end;
---------------------------------------------------------------------------------------------------------------
*/CREATE TABLE time_keeping
(emp_id NUMBER ,keeping_date DATE , transaction_type VARCHAR2(200/*))
---------------------------------------------------------------------------------------------------------------------
procedure calc_prmemium_first_level
(p_value number , p_prm_number number ) --CALCULATE PREMIUMFIRST LEVEL
is
v_item_id number;
v_premium_amount number:= p_value/p_prm_number;
v_outstand_amount number;
begin
v_outstand_amount:=p_value;
select nvl(max(item_id),0)+1 into v_item_id
from premiums;
for i in 1.. p_prm_number loop
v_outstand_amount:= v_outstand_amount-v_premium_amount;
insert into premiums (item_id , premium_id ,premium_amount ,outstand_amount)
values (v_item_id , i ,v_premium_amount ,v_outstand_amount;)
end loop;
end;
---------------------------------------------------------------------------------------------------------------------------
----------
procedure calc_prmemium
(p_value NUMBER , p_prm_number NUMBER,p_deposit_value NUMBER)
IS
v_item_id NUMBER;
v_premium_amount NUMBER:= (p_value-p_deposit_value)/p_prm_number;
v_outstand_amount NUMBER;
v_outstand_amount_1 NUMBER :=p_value-p_deposit_value;
BEGIN
v_outstand_amount:=p_value-p_deposit_value;
select nvl(max(item_id),0)+1 into v_item_id
from premiums;
FOR i in 0.. p_prm_number
loop
IF i <>0 THEN
v_outstand_amount:= v_outstand_amount-v_premium_amount;
END IF;
IF i=0 then
insert into premiums
values (v_item_id , i ,null,p_deposit_value ,v_outstand_amount_1;)
ELSE
insert into premiums
values (v_item_id , i ,v_premium_amount,null ,v_outstand_amount;)
END IF;
END loop;
END;
-----------------------------------------------------------------------------------
*/CREATE TABLE premiums
(item_id number , premium_id number ,premium_amount number,
deposit_amount number ,outstand_amount number/*)
--------------------------------------------------------------------------------------------
PROCEDURE CALC_EMPLOYEE_TAX
(P_EMP_sal NUMBER ) --CALCULATE EMPLOYEE TAX
IS
V_sal number;
V_TAX number;
BEGIN
select salary into V_sal from employees
where EMPLOYEE_id =P_EMP_sal;
V_TAX:= V_sal * 0.02;
if V_sal between 0 and 10000 then V_TAX:= V_sal * 0.05;
elsif V_sal between 10001 and 15000 then V_TAX:= V_sal * 0.1;
elsif V_sal between 15001 and 20000 then V_TAX:= V_sal * 0.15;
elsif V_sal between 20001 and 25000 then V_TAX:= V_sal * 0.20;
elsif V_sal between 25001 and 30000 then V_TAX:= V_sal * 0.25;
else V_TAX:= V_sal * 0.30;
end if;
END;
--------------------------------------------------------------------------------------------------------------
FUNCTION GET_FULL_NAME
(EMP_ID IN NUMBER ) RETURN VARCHAR2 --full name by emp_id
IS
v_full_name VARCHAR2 (200; )
BEGIN
select first_name ||' '||last_name into v_full_name from employees
where employee_id=emp_id;
RETURN v_full_name;
END;
FUNCTION GET_DEPT_NAME_FINAL_TASK
(P_EMP_ID NUMBER ,P_TYPE_E_OR_D departments.department_name%type)
RETURN departments.department_name%type --GET DEPARTMENTT NAME
IS
V_DEPT_NAME departments.department_name%type;
BEGIN
IF upper(P_TYPE_E_OR_D) like 'E' then
SELECT department_name
INTO V_DEPT_NAME
from employees e , departments d
where d.department_id=e.department_id
and employee_id= P_EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The department name for this employee number('||' '||P_EMP_ID||'
'||')is'||' '|| V_DEPT_NAME;)
ELSIF upper(P_TYPE_E_OR_D) like 'D' then
SELECT department_name
INTO V_DEPT_NAME
from departments
where department_id=P_EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The departmentname forthis number('||' '||P_EMP_ID||' '||')is'||' '||
V_DEPT_NAME;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter dept or emp id and (E or D;)' )
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)'
RETURN V_DEPT_NAME;
END;
------------------------------------------
*/declare
v_1 departments.department_name%type;
begin
v_1:= GET_DEPT_NAME_FINAL_TASK(100,'d;)'
end/*;
---------------------------------------------------------------------------------------------------------------------------
----------------
FUNCTION GET_FULL_ADRR_FOR_DEPT_OR_EMP
(DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2
IS
V_FULL_ADRRESS VARCHAR2 (200; )
V_DEPT_NAME VARCHAR2 (200; )
V_EMP_NAME VARCHAR2 (200; )
BEGIN
IF upper(P_TYPE_E_OR_D) like 'E' then
select first_name ||' '||last_name
into V_EMP_NAME
from employees
where employee_id=DEPT_OR_EMP_ID;
SELECT REGION_NAME||' '||COUNTRY_NAME||' '||CITY||' '|| STREET_ADDRESS
into V_FULL_ADRRESS
from employees e , departments d , locations l , countries c , regions r
where e.department_id= d.department_id
and d.location_id = l.location_id
and l.country_id = c.country_id
and c.region_id = r.region_id
and employee_id = DEPT_OR_EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The full adrress for '||' '||V_EMP_NAME ||' '||'emp is
:'||V_FULL_ADRRESS;)
ELSIF upper(P_TYPE_E_OR_D) like 'D' then
SELECT department_name
INTO V_DEPT_NAME
from departments
where department_id=DEPT_OR_EMP_ID;
select REGION_NAME ||'- '|| COUNTRY_NAME ||'- '|| CITY ||'- '|| STREET_ADDRESS
into V_FULL_ADRRESS
from departments d, locations l , countries c , regions r
where d.location_id = l.location_id
and l.country_id = c.country_id
and c.region_id = r.region_id
and department_id = DEPT_OR_EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The full adrress for dept '||' '||V_DEPT_NAME||' is
:'||V_FULL_ADRRESS;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter dept or emp id and (E or D;)' )
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)'
RETURN V_FULL_ADRRESS;
END;
-------------------------------------------------------------------------------------------------------------------------
FUNCTION GET_CITY_FOR_DEPT_OR_EMP
(DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2
IS
V_CITY VARCHAR2 (200; )
V_DEPT_NAME VARCHAR2 (200; )
V_EMP_NAME VARCHAR2 (200; )
BEGIN
IF upper(P_TYPE_E_OR_D) like 'E' then
select first_name ||' '||last_name
into V_EMP_NAME
from employees
where employee_id=DEPT_OR_EMP_ID;
SELECT CITY
into V_CITY
from employees e , departments d , locations l , countries c
where e.department_id= d.department_id
and d.location_id = l.location_id
and l.country_id = c.country_id
and employee_id =DEPT_OR_EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The city name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_CITY;)
ELSIF upper(P_TYPE_E_OR_D) like 'D' then
SELECT department_name
INTO V_DEPT_NAME
from departments
where department_id=DEPT_OR_EMP_ID;
select CITY
into V_CITY
from departments d, locations l , countries c
where d.location_id = l.location_id
and l.country_id = c.country_id
and d.department_id = DEPT_OR_EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The city name for '||' '||V_DEPT_NAME||'dept is :'||' '||V_CITY;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter dept or emp id and (E or D;)' )
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)'
RETURN V_CITY;
END GET_CITY_FOR_DEPT_OR_EMP;
---------------------------------------------------------------------------------------------------------------------------
FUNCTION GET_SAL_CATEGORY
(EMP_ID NUMBER ) ----SAL_CATEGORY by emp_id
RETURN VARCHAR2
IS
v_sal NUMBER;
BEGIN
select salary into v_sal from employees
where employee_id=emp_id;
IF v_sal between 0 and 10000 then RETURN 'A; '
ELSIF v_sal between 10001 and 15000 then RETURN 'B;'
ELSIF v_sal between 15001 and 20000 then RETURN 'C;'
ELSIF v_sal between 20001 and 25000 then RETURN 'D; '
ELSIF v_sal between 25001 and 30000 then RETURN 'E; '
ELSE RETURN 'F; '
END IF;
END;
-----------------------------------------------------------------------------------------------------
FUNCTION GET_SAL_CATG
(P_EMP_sal NUMBER ) -- sal category by amount
RETURN varchar2
IS
V_SAL_CATG number;
BEGIN
select salary into V_SAL_CATG from employees
where employee_id =P_EMP_sal;
if V_SAL_CATG between 0 and 10000 then RETURN 'A; '
elsif V_SAL_CATG between 10001 and 15000 then RETURN 'B;'
elsif V_SAL_CATG between 15001 and 20000 then RETURN 'C;'
elsif V_SAL_CATG between 20001 and 25000 then RETURN 'D; '
elsif V_SAL_CATG between 25001 and 30000 then RETURN 'E; '
else RETURN 'da kteeeeeeeeeeeer; '
end if;
END;
------------------------------------------------------------------------
FUNCTION GET_SINGLE_DETAILS_FOR_EMP
(EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2
IS
V_COUNTRY_NAME VARCHAR2 (200; )
V_DEPT_NAME VARCHAR2 (200; )
V_EMP_NAME VARCHAR2 (200; )
V_CITY VARCHAR2 (200; )
V_REGION_NAME VARCHAR2 (200; )
V_STREET_ADDRESS VARCHAR2 (200; )
BEGIN
IF upper(P_TYPE_E_OR_D) like 'C' then
select first_name ||' '||last_name
into V_EMP_NAME
from employees
where employee_id=EMP_ID;
SELECT CITY
into V_CITY
from employees e , departments d , locations l , countries c
where e.department_id= d.department_id
and d.location_id = l.location_id
and l.country_id = c.country_id
and employee_id =EMP_ID;
SELECT COUNTRY_NAME
into V_COUNTRY_NAME
from employees e , departments d , locations l , countries c
where e.department_id= d.department_id
and d.location_id = l.location_id
and l.country_id = c.country_id
and employee_id =EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The city name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_CITY;)
DBMS_OUTPUT.PUT_LINE ('The country name for '||' '||V_EMP_NAME ||' '||'emp is
:'||V_COUNTRY_NAME;)
ELSIF upper(P_TYPE_E_OR_D) like 'R' then
select first_name ||' '||last_name
into V_EMP_NAME
from employees
where employee_id=EMP_ID;
SELECT REGION_NAME
INTO V_REGION_NAME
from employees e , departments d , locations l , countries c , regions r
where e.department_id= d.department_id
and d.location_id = l.location_id
and l.country_id = c.country_id
and c.region_id = r.region_id
and employee_id = EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The region name for '||' '||V_EMP_NAME ||' '||'emp is
:'||V_COUNTRY_NAME;)
ELSIF upper(P_TYPE_E_OR_D) like 'S' then
SELECT STREET_ADDRESS
INTO V_STREET_ADDRESS
from employees e , departments d , locations l
where e.department_id= d.department_id
and d.location_id = l.location_id
and employee_id = EMP_ID;
DBMS_OUTPUT.PUT_LINE ('The region name for '||' '||V_EMP_NAME ||' '||'emp is
:'||V_STREET_ADDRESS;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (C for city and country,R for regiion or S for
street;)' )
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)'
RETURN V_COUNTRY_NAME;
END;
---------------------------------------------------------------------------------------------------------------------------
-------
FUNCTION F_MGR_Y_N
(EMP_ID NUMBER , P_TYPE_E_OR_D VARCHAR2 )--for emp or dept
RETURN VARCHAR2
IS
CURSOR MGR_Y_N IS
SELECT E.MANAGER_ID FROMEMPLOYEES E , DEPARTMENTS D
where e.DEPARTMENT_id = d.DEPARTMENT_id
AND E.MANAGER_ID = EMP_ID;
v_MGR_Y_N MGR_Y_N%ROWTYPE;
V_MAX_ID NUMBER;
V_MIN_ID NUMBER;
V_MGR_ID NUMBER;
BEGIN
IF upper(P_TYPE_E_OR_D) like 'E' then
SELECT EMPLOYEE_id
into V_MGR_ID
from employees
where manager_id =EMP_ID;
IF V_MGR_ID IS NULL THEN
dbms_output.put_line ('N;)'
ELSE dbms_output.put_line ('Y;)'
END IF;
ELSIF upper(P_TYPE_E_OR_D) like 'D' then
SELECT E.MANAGER_ID
INTO V_MGR_ID
FROM EMPLOYEES E , DEPARTMENTS D
where e.DEPARTMENT_id = d.DEPARTMENT_id
AND E.MANAGER_ID = EMP_ID;
IF V_MGR_ID IS NULL THEN
dbms_output.put_line ('N;)'
ELSE dbms_output.put_line ('Y;)'
END IF;
END IF;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
dbms_output.put_line ('Y;)'
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('N;)'
WHEN OTHERS THEN
dbms_output.put_line ('INVALID ID;)'
END;
---------------------------------------------------------------------------------------------
FUNCTION F_COMM_Y_N
(EMP_ID NUMBER)
RETURN VARCHAR2
IS
V_COMM NUMBER;
BEGIN
SELECT COMMISSION_PCT
INTO V_COMM
FROMEMPLOYEES
WHERE EMPLOYEE_ID = EMP_ID;
IF V_COMM IS NULL THEN
dbms_output.put_line ('Tis employee dont have commition;)'
ELSE
dbms_output.put_line (' Tis employee have commition;)'
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp ID;)'
RETURN V_COMM;
END;
--------------------------------------------------------------------------------------------
FUNCTION MIN_MAX_SALARY_DIFFERENCE
(EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 )--for emp or dept
RETURN number
IS
V_DIFF_SAL NUMBER;
V_EMP_SAL NUMBER;
V_MAX_SAL NUMBER;
V_MIN_SAL NUMBER;
V_EMP_NAME VARCHAR2 (200; )
BEGIN
select first_name ||' '||last_name
into V_EMP_NAME
from employees
where employee_id=EMP_ID;
select salary
into V_EMP_SAL
from employees
where employee_id=EMP_ID;
SELECT MAX(salary)
into V_MAX_SAL
from employees;
SELECT MIN(salary)
into V_MIN_SAL
from employees;
IF upper(P_TYPE_M_OR_N) like 'M' then
V_DIFF_SAL:=V_MAX_SAL-V_EMP_SAL;
DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||''||V_EMP_NAME||''||'salaryand max
salary is
(max salary - emp salary) '||V_MAX_SAL||'-'||V_EMP_SAL||'='||V_DIFF_SAL;)
ELSIF upper(P_TYPE_M_OR_N) like 'N' then
V_DIFF_SAL:=V_EMP_SAL-V_MIN_SAL;
DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||''||V_EMP_NAME||' '||'and min salary
is
(emp salary - min salary) '||V_EMP_SAL||'-'||V_MIN_SAL||'='||V_DIFF_SAL;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (Mor N;)' )
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp ID;)'
RETURN V_DIFF_SAL;
END;
---------------------------------------------------------------------------------------------------------------------------
---
FUNCTION MIN_MAX_SAL_DIFFR_with_SCALE --MIN_MAX_SALary_DIFFRence_with_SCALE (id,'m
or n ','g or d') SCALE (GENERAL OR PER DEPT)
(EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 ,P_SCALE VARCHAR2 )--for emp or dept
RETURN number
IS
V_DEPT_ID NUMBER;
V_DEPT_AVG_SAL NUMBER;
V_DIFF_SAL NUMBER;
V_EMP_SAL NUMBER;
V_MAX_SAL NUMBER;
V_DEPT_MAX_SAL NUMBER;
V_DEPT_MIN_SAL NUMBER;
V_MIN_SAL NUMBER;
V_EMP_NAME VARCHAR2 (200; )
BEGIN
select first_name ||' '||last_name
into V_EMP_NAME
from employees
where employee_id=EMP_ID;
select department_id
into V_DEPT_ID
from employees
where employee_id=EMP_ID;
select avg(salary)
into V_DEPT_AVG_SAL
from employees
where department_id=V_DEPT_ID;
select salary
into V_EMP_SAL
from employees
where employee_id=EMP_ID;
SELECT MAX(salary)
into V_MAX_SAL
from employees;
SELECT MAX(salary)
into V_DEPT_MAX_SAL
from employees
where department_id=V_DEPT_ID;
SELECT MIN(salary)
into V_DEPT_MIN_SAL
from employees
where department_id=V_DEPT_ID;
SELECT MIN(salary)
into V_MIN_SAL
from employees;
IF upper(P_SCALE) like 'G' then
IF upper(P_TYPE_M_OR_N) like 'M' then
V_DIFF_SAL:=V_MAX_SAL-V_EMP_SAL;
DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||' '||V_EMP_NAME||''||'salaryand max
salary is
(max salary - emp salary) '||V_MAX_SAL||'-'||V_EMP_SAL||'='||V_DIFF_SAL;)
ELSIF upper(P_TYPE_M_OR_N) like 'N' then
V_DIFF_SAL:=V_EMP_SAL-V_MIN_SAL;
DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||''||V_EMP_NAME||' '||'and min salary
is
(emp salary - min salary) '||V_EMP_SAL||'-'||V_MIN_SAL||'='||V_DIFF_SAL;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (Mor N and G or D;)' )
END IF;
ELSIF upper(P_SCALE) like 'D' then
IF upper(P_TYPE_M_OR_N) like 'M' then
V_DIFF_SAL:=V_DEPT_MAX_SAL-V_EMP_SAL;
DBMS_OUTPUT.PUT_LINE ('The difference between emp:'||' '||V_EMP_NAME||' '||'salary and
dept max salary is
(dept max salary - emp salary) '||V_DEPT_MAX_SAL||'-'||V_EMP_SAL||'='||V_DIFF_SAL;)
ELSIF upper(P_TYPE_M_OR_N) like 'N' then
V_DIFF_SAL:=V_EMP_SAL-V_DEPT_MIN_SAL;
DBMS_OUTPUT.PUT_LINE ('The difference between emp:'||' '||V_EMP_NAME||' '||'and dept min
salary is
(dept emp salary - min salary) '||V_EMP_SAL||'-'||V_DEPT_MIN_SAL||'='||V_DIFF_SAL;)
ELSE
DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (Mor N and G or D;)' )
END IF;
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp ID;)'
RETURN V_DIFF_SAL;
END;
---------------------------------------------------------------------------------------------------------------------------
-----
END YM_PKG_PL_TASK;
‫ش‬

More Related Content

Similar to PL_PKG_TASK

Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Thuan Nguyen
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 
Oracle - Program with PL/SQL - Lession 07
Oracle - Program with PL/SQL - Lession 07Oracle - Program with PL/SQL - Lession 07
Oracle - Program with PL/SQL - Lession 07Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Thuan Nguyen
 
How to create payslip through self service
How to create payslip through self serviceHow to create payslip through self service
How to create payslip through self serviceFeras Ahmad
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfpnaran46
 
Create Stored Procedure & Package
Create Stored Procedure & PackageCreate Stored Procedure & Package
Create Stored Procedure & PackageLakshendraSingh
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesLucas Jellema
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Thuan Nguyen
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docxajoy21
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxgilpinleeanna
 
5.procesos
5.procesos 5.procesos
5.procesos Taringa!
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfarmanuelraj
 
Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Thuan Nguyen
 
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfoperating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfarasanmobiles
 
Write a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdfWrite a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdfarihantgiftgallery
 
Adding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMPAdding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMPJacques Rioux
 

Similar to PL_PKG_TASK (20)

Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Oracle - Program with PL/SQL - Lession 07
Oracle - Program with PL/SQL - Lession 07Oracle - Program with PL/SQL - Lession 07
Oracle - Program with PL/SQL - Lession 07
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03
 
How to create payslip through self service
How to create payslip through self serviceHow to create payslip through self service
How to create payslip through self service
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdf
 
Create Stored Procedure & Package
Create Stored Procedure & PackageCreate Stored Procedure & Package
Create Stored Procedure & Package
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practices
 
Xenogenetics
XenogeneticsXenogenetics
Xenogenetics
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docx
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
5.procesos
5.procesos 5.procesos
5.procesos
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
 
Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10Oracle - Program with PL/SQL - Lession 10
Oracle - Program with PL/SQL - Lession 10
 
Fx oracle - AS400
Fx oracle - AS400Fx oracle - AS400
Fx oracle - AS400
 
Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05
 
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfoperating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
 
Write a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdfWrite a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdf
 
Adding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMPAdding Statistical Functionality to the DATA Step with PROC FCMP
Adding Statistical Functionality to the DATA Step with PROC FCMP
 

PL_PKG_TASK

  • 1. CREATE OR REPLACE PACKAGE YM_PKG_PL_TASK IS PROCEDURE MIN_MAX_SALARY_DIFFERENCE --PROCEDURE FPR MINIMUMAND MAXIMUM SALARY DIFFERENCE (EMP_ID in NUMBER,WEIGHT_COMPANY IN VARCHAR2, WEIGHT_DEPT IN VARCHAR2, P_SALARY OUT NUMBER ,P_MIN_SALARY OUT NUMBER,P_MAX_SALARY OUT NUMBER; ) PROCEDURE increase_emp_salary_if_task (p_emp_id number ,p_increase varchar2 , p_value number;) */create table time_keeping (emp_id number ,keeping_date date , transaction_type varchar2(200/*) ) ------------------------------------------------------------------------------------ PROCEDURE keeping_time (p_emp_id number ,p_status varchar2;) --------------------------------------------- */CREATE TABLE time_keeping (emp_id NUMBER ,keeping_date DATE , transaction_type VARCHAR2(200/*)) ---------------------------------------------------------------------------------------------------
  • 2. procedure calc_prmemium_first_level --CALCULATE PREMIUMFIRST LEVEL (p_value number , p_prm_number number;) procedure calc_prmemium (p_value NUMBER , p_prm_number NUMBER,p_deposit_value NUMBER ); -- SECOND_PREM_TASK_level ----------------------------------------------------------------------------------- */CREATE TABLE premiums (item_id number , premium_id number ,premium_amount number, deposit_amount number ,outstand_amount number/*) -------------------------------------------------------------------------------------------- PROCEDURE CALC_EMPLOYEE_TAX (P_EMP_sal NUMBER ); --CALCULATE EMPLOYEE TAX
  • 3. FUNCTION GET_FULL_NAME (EMP_ID IN NUMBER ) RETURN VARCHAR2 ; --full name by emp_id FUNCTION GET_DEPT_NAME_FINAL_TASK (P_EMP_ID NUMBER ,P_TYPE_E_OR_D departments.department_name%type) RETURN departments.department_name%type ; --GET DEPARTMENTT NAME FUNCTION GET_FULL_ADRR_FOR_DEPT_OR_EMP (DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2; FUNCTION GET_CITY_FOR_DEPT_OR_EMP (DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2; FUNCTION GET_SAL_CATEGORY (EMP_ID NUMBER ) --SAL_CATEGORY by emp_id RETURN VARCHAR2;
  • 4. FUNCTION GET_SAL_CATG (P_EMP_sal NUMBER ) --sal category by amount RETURN varchar2; FUNCTION GET_SINGLE_DETAILS_FOR_EMP (EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2; FUNCTION F_MGR_Y_N (EMP_ID NUMBER , P_TYPE_E_OR_D VARCHAR2 ) --THIS EMPLOYEE ID IS MANAGER OR NOT ? for emps or dept RETURN VARCHAR2; FUNCTION F_COMM_Y_N (EMP_ID NUMBER ) --THIS EMPLOYEE HAVE COMMISSION OR NOT RETURN (Y OR N) RETURN VARCHAR2; FUNCTION MIN_MAX_SALARY_DIFFERENCE (EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 ) --MIN_MAX_SALARY_DIFFERENCE for emp or dept
  • 5. RETURN number; FUNCTION MIN_MAX_SAL_DIFFR_WITH_SCALE --MIN_MAX_SALary_DIFFRence_with_SCALE (id,'m or n ','g or d') SCALE (GENERAL OR PER DEPT) (EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 ,P_SCALE VARCHAR2 )--for emp or dept RETURN number; END YM_PKG_PL_TASK; BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOODDD DDDDDDDDDDDDDDYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY CREATE OR REPLACE PACKAGE BODY YM_PKG_PL_TASK IS
  • 6. PROCEDURE MIN_MAX_SALARY_DIFFERENCE --PROCEDURE FPR MINIMUMAND MAXIMUM SALARY DIFFERENCE (EMP_ID in NUMBER,WEIGHT_COMPANY IN VARCHAR2, WEIGHT_DEPT IN VARCHAR2, P_SALARY OUT NUMBER ,P_MIN_SALARY OUT NUMBER,P_MAX_SALARY OUT NUMBER) IS V_JOB_ID employees.job_id%TYPE; V_SALARY NUMBER; V_DEPT_ID NUMBER; V_SUM_SAL NUMBER; V_SUM_SAL_DEPT NUMBER; V_PERC_FOR_COM NUMBER; V_PERC_FOR_DEPT NUMBER; BEGIN IF upper(WEIGHT_COMPANY) like 'C' AND upper(WEIGHT_DEPT) like 'D' then SELECT salary INTO P_SALARY
  • 7. FROM employees WHERE employee_id=EMP_ID; SELECT min(salary), max(salary) INTO P_MIN_SALARY ,P_MAX_SALARY FROM employees WHERE job_id=V_JOB_ID; SELECT job_id INTO V_JOB_ID FROM employees WHERE employee_id=EMP_ID; SELECT salary INTO V_SALARY FROM employees WHERE employee_id=EMP_ID; SELECT DEPARTMENT_ID INTO V_DEPT_ID FROM employees WHERE employee_id=EMP_ID; SELECT SUM(salary) INTO V_SUM_SAL FROM employees; SELECT SUM(salary)
  • 8. INTO V_SUM_SAL_DEPT FROM employees WHERE DEPARTMENT_ID=V_DEPT_ID; V_PERC_FOR_COM :=SUBSTR( V_SALARY/V_SUM_SAL,0,4; ) V_PERC_FOR_DEPT :=SUBSTR( V_SALARY/V_SUM_SAL_DEPT,2,2; ) DBMS_OUTPUT.PUT_LINE ('SALARY IS :'||' '||P_SALARY ||' '||'MIN SALARY IS: ||' '||'P_MIN_SALARY ||' '||'MAX SALARY IS :'|| P_MAX_SALARY||' '||'FOR '||'( '||V_JOB_ID||')'||'JOB;)' DBMS_OUTPUT.PUT_LINE('HIS SALARY REPRESENTS '||' '||V_PERC_FOR_COM||'%'||'FROM COMPANY SALARIES;)' DBMS_OUTPUT.PUT_LINE(' AND HIS SALARY REPRESENTS '||' '||V_PERC_FOR_DEPT||'%'||'FROM HIS DEPT SALARIES;) ' ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp id and (C and D;)' ) END IF; end; --------------------------------------------------------------------------------------------------------------------------- ----
  • 9. --INCREASE SALARY BY USING IF STATEMENT PROCEDURE increase_emp_salary_if_task ( p_emp_id number ,p_increase varchar2 , p_value number) is v_dept_sal_avg EMPLOYEES.SALARY%type; v_sal_avg EMPLOYEES.SALARY%type; v_sal EMPLOYEES.SALARY%type; v_value number; v_dept_id number; v_emp_name varchar2 (200;) begin select department_id into v_dept_id from employees where employee_id = p_emp_id; select avg(salary)into v_dept_sal_avg from employees where department_id =v_dept_id; select avg(salary)into v_sal_avg from employees; select first_name||' '||last_name into v_emp_name from employees where employee_id = p_emp_id;
  • 10. select salary into v_sal from employees where employee_id = p_emp_id; if upper (p_increase) like 'A' then select avg(salary)into v_dept_sal_avg from employees where department_id =v_dept_id; if p_value >v_dept_sal_avg then DBMS_OUTPUT.PUT_LINE ('these amount larger thane '||my_pkg.get_dept_name(p_emp_id)||' department salary AVG;)' else update employees set salary=salary+p_value where employee_id = p_emp_id; if sql%found then insert into update_emp_salary_details (user_id ,increase_date , emp_name_increase ,sal_bef_increase ,sal_aft_increase ,increase_amount,increase_type) values (user ,sysdate ,v_emp_name,v_sal,v_sal+p_value,p_value,'increased by amount;)' end if;
  • 11. DBMS_OUTPUT.PUT_LINE ('salary is increased;)' end if; elsif upper (p_increase)like 'P' then v_value:=p_value/v_sal; if v_value >= .99 then DBMS_OUTPUT.PUT_LINE ('these amount larger thane current salary;)' else if v_sal+(v_sal*v_value) > v_sal_avg then DBMS_OUTPUT.PUT_LINE ('salary larger than the'||' '||''||my_pkg.get_dept_name(p_emp_id)||''||' '||' department salary AVG;)' else update employees set salary=salary+salary*v_value where employee_id = p_emp_id;
  • 12. if sql%found then insert into update_emp_salary_details (user_id ,increase_date , emp_name_increase ,sal_bef_increase ,sal_aft_increase ,increase_amount,increase_type) values(user,sysdate ,v_emp_name,v_sal,v_sal+(v_sal*v_value),p_value,'increasedbypercentage;)' end if; DBMS_OUTPUT.PUT_LINE ('salary % is increased;)' end if; end if; end if; end; ------------------------------------------------------------------------- */create table time_keeping (emp_id number ,keeping_date date , transaction_type varchar2(200/*) ) --------------------------------------------------------------------------------------------------------------------------- ---------------------
  • 13. PROCEDURE keeping_time (p_emp_id number ,p_status varchar2) is v_emp_name varchar2(200;) begin select first_name||' '||last_name into v_emp_name from employees where employee_id = p_emp_id; if upper (p_status) like 'I' then insert into time_keeping (emp_id ,keeping_date , transaction_type) values (p_emp_id,to_char (systimestamp,'fmdd/mm/yyyy- hh24:mi:ss'),upper (p_status; ) ) DBMS_OUTPUT.PUT_LINE('The employee'||': '||initcap(v_emp_name)||' '||'is enrolled IN;)' elsif upper (p_status) like 'O' then insert into time_keeping (emp_id ,keeping_date , transaction_type) values (p_emp_id,to_char (systimestamp,'fmdd/mm/yyyy- hh24:mi:ss' ),upper (p_status; ) ) DBMS_OUTPUT.PUT_LINE('The employee'||': '||initcap(v_emp_name)||' '||'is enrolled OUT;)' end if; end;
  • 14. --------------------------------------------------------------------------------------------------------------- */CREATE TABLE time_keeping (emp_id NUMBER ,keeping_date DATE , transaction_type VARCHAR2(200/*)) --------------------------------------------------------------------------------------------------------------------- procedure calc_prmemium_first_level (p_value number , p_prm_number number ) --CALCULATE PREMIUMFIRST LEVEL is v_item_id number; v_premium_amount number:= p_value/p_prm_number; v_outstand_amount number; begin v_outstand_amount:=p_value; select nvl(max(item_id),0)+1 into v_item_id from premiums; for i in 1.. p_prm_number loop v_outstand_amount:= v_outstand_amount-v_premium_amount; insert into premiums (item_id , premium_id ,premium_amount ,outstand_amount) values (v_item_id , i ,v_premium_amount ,v_outstand_amount;) end loop;
  • 15. end; --------------------------------------------------------------------------------------------------------------------------- ---------- procedure calc_prmemium (p_value NUMBER , p_prm_number NUMBER,p_deposit_value NUMBER) IS v_item_id NUMBER; v_premium_amount NUMBER:= (p_value-p_deposit_value)/p_prm_number; v_outstand_amount NUMBER; v_outstand_amount_1 NUMBER :=p_value-p_deposit_value; BEGIN v_outstand_amount:=p_value-p_deposit_value; select nvl(max(item_id),0)+1 into v_item_id from premiums; FOR i in 0.. p_prm_number loop IF i <>0 THEN v_outstand_amount:= v_outstand_amount-v_premium_amount; END IF; IF i=0 then insert into premiums values (v_item_id , i ,null,p_deposit_value ,v_outstand_amount_1;)
  • 16. ELSE insert into premiums values (v_item_id , i ,v_premium_amount,null ,v_outstand_amount;) END IF; END loop; END; ----------------------------------------------------------------------------------- */CREATE TABLE premiums (item_id number , premium_id number ,premium_amount number, deposit_amount number ,outstand_amount number/*) -------------------------------------------------------------------------------------------- PROCEDURE CALC_EMPLOYEE_TAX (P_EMP_sal NUMBER ) --CALCULATE EMPLOYEE TAX IS V_sal number; V_TAX number;
  • 17. BEGIN select salary into V_sal from employees where EMPLOYEE_id =P_EMP_sal; V_TAX:= V_sal * 0.02; if V_sal between 0 and 10000 then V_TAX:= V_sal * 0.05; elsif V_sal between 10001 and 15000 then V_TAX:= V_sal * 0.1; elsif V_sal between 15001 and 20000 then V_TAX:= V_sal * 0.15; elsif V_sal between 20001 and 25000 then V_TAX:= V_sal * 0.20; elsif V_sal between 25001 and 30000 then V_TAX:= V_sal * 0.25; else V_TAX:= V_sal * 0.30; end if; END; -------------------------------------------------------------------------------------------------------------- FUNCTION GET_FULL_NAME (EMP_ID IN NUMBER ) RETURN VARCHAR2 --full name by emp_id IS v_full_name VARCHAR2 (200; ) BEGIN select first_name ||' '||last_name into v_full_name from employees where employee_id=emp_id; RETURN v_full_name; END;
  • 18. FUNCTION GET_DEPT_NAME_FINAL_TASK (P_EMP_ID NUMBER ,P_TYPE_E_OR_D departments.department_name%type) RETURN departments.department_name%type --GET DEPARTMENTT NAME IS V_DEPT_NAME departments.department_name%type; BEGIN IF upper(P_TYPE_E_OR_D) like 'E' then SELECT department_name INTO V_DEPT_NAME from employees e , departments d where d.department_id=e.department_id and employee_id= P_EMP_ID; DBMS_OUTPUT.PUT_LINE ('The department name for this employee number('||' '||P_EMP_ID||' '||')is'||' '|| V_DEPT_NAME;) ELSIF upper(P_TYPE_E_OR_D) like 'D' then SELECT department_name INTO V_DEPT_NAME from departments where department_id=P_EMP_ID; DBMS_OUTPUT.PUT_LINE ('The departmentname forthis number('||' '||P_EMP_ID||' '||')is'||' '|| V_DEPT_NAME;)
  • 19. ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter dept or emp id and (E or D;)' ) END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)' RETURN V_DEPT_NAME; END; ------------------------------------------ */declare v_1 departments.department_name%type; begin v_1:= GET_DEPT_NAME_FINAL_TASK(100,'d;)' end/*;
  • 20. --------------------------------------------------------------------------------------------------------------------------- ---------------- FUNCTION GET_FULL_ADRR_FOR_DEPT_OR_EMP (DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2 IS V_FULL_ADRRESS VARCHAR2 (200; ) V_DEPT_NAME VARCHAR2 (200; ) V_EMP_NAME VARCHAR2 (200; ) BEGIN IF upper(P_TYPE_E_OR_D) like 'E' then select first_name ||' '||last_name into V_EMP_NAME from employees where employee_id=DEPT_OR_EMP_ID; SELECT REGION_NAME||' '||COUNTRY_NAME||' '||CITY||' '|| STREET_ADDRESS into V_FULL_ADRRESS from employees e , departments d , locations l , countries c , regions r where e.department_id= d.department_id and d.location_id = l.location_id
  • 21. and l.country_id = c.country_id and c.region_id = r.region_id and employee_id = DEPT_OR_EMP_ID; DBMS_OUTPUT.PUT_LINE ('The full adrress for '||' '||V_EMP_NAME ||' '||'emp is :'||V_FULL_ADRRESS;) ELSIF upper(P_TYPE_E_OR_D) like 'D' then SELECT department_name INTO V_DEPT_NAME from departments where department_id=DEPT_OR_EMP_ID; select REGION_NAME ||'- '|| COUNTRY_NAME ||'- '|| CITY ||'- '|| STREET_ADDRESS into V_FULL_ADRRESS from departments d, locations l , countries c , regions r where d.location_id = l.location_id and l.country_id = c.country_id and c.region_id = r.region_id and department_id = DEPT_OR_EMP_ID; DBMS_OUTPUT.PUT_LINE ('The full adrress for dept '||' '||V_DEPT_NAME||' is :'||V_FULL_ADRRESS;) ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter dept or emp id and (E or D;)' ) END IF;
  • 22. EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)' RETURN V_FULL_ADRRESS; END; ------------------------------------------------------------------------------------------------------------------------- FUNCTION GET_CITY_FOR_DEPT_OR_EMP (DEPT_OR_EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2 IS V_CITY VARCHAR2 (200; ) V_DEPT_NAME VARCHAR2 (200; ) V_EMP_NAME VARCHAR2 (200; ) BEGIN IF upper(P_TYPE_E_OR_D) like 'E' then select first_name ||' '||last_name into V_EMP_NAME from employees where employee_id=DEPT_OR_EMP_ID;
  • 23. SELECT CITY into V_CITY from employees e , departments d , locations l , countries c where e.department_id= d.department_id and d.location_id = l.location_id and l.country_id = c.country_id and employee_id =DEPT_OR_EMP_ID; DBMS_OUTPUT.PUT_LINE ('The city name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_CITY;) ELSIF upper(P_TYPE_E_OR_D) like 'D' then SELECT department_name INTO V_DEPT_NAME from departments where department_id=DEPT_OR_EMP_ID; select CITY into V_CITY from departments d, locations l , countries c where d.location_id = l.location_id and l.country_id = c.country_id and d.department_id = DEPT_OR_EMP_ID; DBMS_OUTPUT.PUT_LINE ('The city name for '||' '||V_DEPT_NAME||'dept is :'||' '||V_CITY;) ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter dept or emp id and (E or D;)' )
  • 24. END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)' RETURN V_CITY; END GET_CITY_FOR_DEPT_OR_EMP; --------------------------------------------------------------------------------------------------------------------------- FUNCTION GET_SAL_CATEGORY (EMP_ID NUMBER ) ----SAL_CATEGORY by emp_id RETURN VARCHAR2 IS v_sal NUMBER; BEGIN select salary into v_sal from employees where employee_id=emp_id; IF v_sal between 0 and 10000 then RETURN 'A; ' ELSIF v_sal between 10001 and 15000 then RETURN 'B;' ELSIF v_sal between 15001 and 20000 then RETURN 'C;' ELSIF v_sal between 20001 and 25000 then RETURN 'D; '
  • 25. ELSIF v_sal between 25001 and 30000 then RETURN 'E; ' ELSE RETURN 'F; ' END IF; END; ----------------------------------------------------------------------------------------------------- FUNCTION GET_SAL_CATG (P_EMP_sal NUMBER ) -- sal category by amount RETURN varchar2 IS V_SAL_CATG number; BEGIN select salary into V_SAL_CATG from employees where employee_id =P_EMP_sal; if V_SAL_CATG between 0 and 10000 then RETURN 'A; ' elsif V_SAL_CATG between 10001 and 15000 then RETURN 'B;' elsif V_SAL_CATG between 15001 and 20000 then RETURN 'C;' elsif V_SAL_CATG between 20001 and 25000 then RETURN 'D; ' elsif V_SAL_CATG between 25001 and 30000 then RETURN 'E; ' else RETURN 'da kteeeeeeeeeeeer; ' end if;
  • 26. END; ------------------------------------------------------------------------ FUNCTION GET_SINGLE_DETAILS_FOR_EMP (EMP_ID NUMBER,P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2 IS V_COUNTRY_NAME VARCHAR2 (200; ) V_DEPT_NAME VARCHAR2 (200; ) V_EMP_NAME VARCHAR2 (200; ) V_CITY VARCHAR2 (200; ) V_REGION_NAME VARCHAR2 (200; ) V_STREET_ADDRESS VARCHAR2 (200; ) BEGIN IF upper(P_TYPE_E_OR_D) like 'C' then select first_name ||' '||last_name into V_EMP_NAME from employees where employee_id=EMP_ID; SELECT CITY
  • 27. into V_CITY from employees e , departments d , locations l , countries c where e.department_id= d.department_id and d.location_id = l.location_id and l.country_id = c.country_id and employee_id =EMP_ID; SELECT COUNTRY_NAME into V_COUNTRY_NAME from employees e , departments d , locations l , countries c where e.department_id= d.department_id and d.location_id = l.location_id and l.country_id = c.country_id and employee_id =EMP_ID; DBMS_OUTPUT.PUT_LINE ('The city name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_CITY;) DBMS_OUTPUT.PUT_LINE ('The country name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_COUNTRY_NAME;) ELSIF upper(P_TYPE_E_OR_D) like 'R' then select first_name ||' '||last_name into V_EMP_NAME from employees where employee_id=EMP_ID; SELECT REGION_NAME
  • 28. INTO V_REGION_NAME from employees e , departments d , locations l , countries c , regions r where e.department_id= d.department_id and d.location_id = l.location_id and l.country_id = c.country_id and c.region_id = r.region_id and employee_id = EMP_ID; DBMS_OUTPUT.PUT_LINE ('The region name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_COUNTRY_NAME;) ELSIF upper(P_TYPE_E_OR_D) like 'S' then SELECT STREET_ADDRESS INTO V_STREET_ADDRESS from employees e , departments d , locations l where e.department_id= d.department_id and d.location_id = l.location_id and employee_id = EMP_ID; DBMS_OUTPUT.PUT_LINE ('The region name for '||' '||V_EMP_NAME ||' '||'emp is :'||V_STREET_ADDRESS;) ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (C for city and country,R for regiion or S for street;)' ) END IF;
  • 29. EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid dept or emp ID;)' RETURN V_COUNTRY_NAME; END; --------------------------------------------------------------------------------------------------------------------------- ------- FUNCTION F_MGR_Y_N (EMP_ID NUMBER , P_TYPE_E_OR_D VARCHAR2 )--for emp or dept RETURN VARCHAR2 IS CURSOR MGR_Y_N IS SELECT E.MANAGER_ID FROMEMPLOYEES E , DEPARTMENTS D where e.DEPARTMENT_id = d.DEPARTMENT_id AND E.MANAGER_ID = EMP_ID; v_MGR_Y_N MGR_Y_N%ROWTYPE; V_MAX_ID NUMBER; V_MIN_ID NUMBER; V_MGR_ID NUMBER; BEGIN IF upper(P_TYPE_E_OR_D) like 'E' then
  • 30. SELECT EMPLOYEE_id into V_MGR_ID from employees where manager_id =EMP_ID; IF V_MGR_ID IS NULL THEN dbms_output.put_line ('N;)' ELSE dbms_output.put_line ('Y;)' END IF; ELSIF upper(P_TYPE_E_OR_D) like 'D' then SELECT E.MANAGER_ID INTO V_MGR_ID FROM EMPLOYEES E , DEPARTMENTS D where e.DEPARTMENT_id = d.DEPARTMENT_id AND E.MANAGER_ID = EMP_ID; IF V_MGR_ID IS NULL THEN dbms_output.put_line ('N;)' ELSE dbms_output.put_line ('Y;)' END IF; END IF; EXCEPTION WHEN TOO_MANY_ROWS THEN
  • 31. dbms_output.put_line ('Y;)' WHEN NO_DATA_FOUND THEN dbms_output.put_line ('N;)' WHEN OTHERS THEN dbms_output.put_line ('INVALID ID;)' END; --------------------------------------------------------------------------------------------- FUNCTION F_COMM_Y_N (EMP_ID NUMBER) RETURN VARCHAR2 IS V_COMM NUMBER; BEGIN SELECT COMMISSION_PCT INTO V_COMM FROMEMPLOYEES WHERE EMPLOYEE_ID = EMP_ID; IF V_COMM IS NULL THEN dbms_output.put_line ('Tis employee dont have commition;)'
  • 32. ELSE dbms_output.put_line (' Tis employee have commition;)' END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp ID;)' RETURN V_COMM; END; -------------------------------------------------------------------------------------------- FUNCTION MIN_MAX_SALARY_DIFFERENCE (EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 )--for emp or dept RETURN number IS V_DIFF_SAL NUMBER; V_EMP_SAL NUMBER; V_MAX_SAL NUMBER; V_MIN_SAL NUMBER;
  • 33. V_EMP_NAME VARCHAR2 (200; ) BEGIN select first_name ||' '||last_name into V_EMP_NAME from employees where employee_id=EMP_ID; select salary into V_EMP_SAL from employees where employee_id=EMP_ID; SELECT MAX(salary) into V_MAX_SAL from employees; SELECT MIN(salary) into V_MIN_SAL from employees; IF upper(P_TYPE_M_OR_N) like 'M' then V_DIFF_SAL:=V_MAX_SAL-V_EMP_SAL; DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||''||V_EMP_NAME||''||'salaryand max salary is (max salary - emp salary) '||V_MAX_SAL||'-'||V_EMP_SAL||'='||V_DIFF_SAL;)
  • 34. ELSIF upper(P_TYPE_M_OR_N) like 'N' then V_DIFF_SAL:=V_EMP_SAL-V_MIN_SAL; DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||''||V_EMP_NAME||' '||'and min salary is (emp salary - min salary) '||V_EMP_SAL||'-'||V_MIN_SAL||'='||V_DIFF_SAL;) ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (Mor N;)' ) END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp ID;)' RETURN V_DIFF_SAL; END; --------------------------------------------------------------------------------------------------------------------------- --- FUNCTION MIN_MAX_SAL_DIFFR_with_SCALE --MIN_MAX_SALary_DIFFRence_with_SCALE (id,'m or n ','g or d') SCALE (GENERAL OR PER DEPT) (EMP_ID NUMBER,P_TYPE_M_OR_N VARCHAR2 ,P_SCALE VARCHAR2 )--for emp or dept
  • 35. RETURN number IS V_DEPT_ID NUMBER; V_DEPT_AVG_SAL NUMBER; V_DIFF_SAL NUMBER; V_EMP_SAL NUMBER; V_MAX_SAL NUMBER; V_DEPT_MAX_SAL NUMBER; V_DEPT_MIN_SAL NUMBER; V_MIN_SAL NUMBER; V_EMP_NAME VARCHAR2 (200; ) BEGIN select first_name ||' '||last_name into V_EMP_NAME from employees where employee_id=EMP_ID; select department_id into V_DEPT_ID from employees where employee_id=EMP_ID; select avg(salary) into V_DEPT_AVG_SAL from employees where department_id=V_DEPT_ID;
  • 36. select salary into V_EMP_SAL from employees where employee_id=EMP_ID; SELECT MAX(salary) into V_MAX_SAL from employees; SELECT MAX(salary) into V_DEPT_MAX_SAL from employees where department_id=V_DEPT_ID; SELECT MIN(salary) into V_DEPT_MIN_SAL from employees where department_id=V_DEPT_ID; SELECT MIN(salary) into V_MIN_SAL from employees; IF upper(P_SCALE) like 'G' then IF upper(P_TYPE_M_OR_N) like 'M' then V_DIFF_SAL:=V_MAX_SAL-V_EMP_SAL;
  • 37. DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||' '||V_EMP_NAME||''||'salaryand max salary is (max salary - emp salary) '||V_MAX_SAL||'-'||V_EMP_SAL||'='||V_DIFF_SAL;) ELSIF upper(P_TYPE_M_OR_N) like 'N' then V_DIFF_SAL:=V_EMP_SAL-V_MIN_SAL; DBMS_OUTPUT.PUT_LINE ('The differencebetweenemp:'||''||V_EMP_NAME||' '||'and min salary is (emp salary - min salary) '||V_EMP_SAL||'-'||V_MIN_SAL||'='||V_DIFF_SAL;) ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (Mor N and G or D;)' ) END IF; ELSIF upper(P_SCALE) like 'D' then IF upper(P_TYPE_M_OR_N) like 'M' then V_DIFF_SAL:=V_DEPT_MAX_SAL-V_EMP_SAL; DBMS_OUTPUT.PUT_LINE ('The difference between emp:'||' '||V_EMP_NAME||' '||'salary and dept max salary is (dept max salary - emp salary) '||V_DEPT_MAX_SAL||'-'||V_EMP_SAL||'='||V_DIFF_SAL;) ELSIF upper(P_TYPE_M_OR_N) like 'N' then V_DIFF_SAL:=V_EMP_SAL-V_DEPT_MIN_SAL;
  • 38. DBMS_OUTPUT.PUT_LINE ('The difference between emp:'||' '||V_EMP_NAME||' '||'and dept min salary is (dept emp salary - min salary) '||V_EMP_SAL||'-'||V_DEPT_MIN_SAL||'='||V_DIFF_SAL;) ELSE DBMS_OUTPUT.PUT_LINE ('Pleas enter emp id and (Mor N and G or D;)' ) END IF; END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('Pleas enter a valid emp ID;)' RETURN V_DIFF_SAL; END; --------------------------------------------------------------------------------------------------------------------------- ----- END YM_PKG_PL_TASK;