PLSQL
PLSQL
da 50%of salary
hra 40%of salary
pf 5%of salary
gross salary+da+hra
netpay gross-pf
also use exception
CODE---
DECLARE
e_code Employees.code%type;
e_salary Employees.salary%type;
p_da pay.da%type;
p_hra pay.hra%type;
d_pf deduction.pf%type;
f_gross final.gross%type;
f_netpay final.netpay%type;
BEGIN
SELECT salary code from Employees;
EXCEPTION
EXIT WHEN salary%Notfound
dbms_output.put_line("record not found");
END;
/
DECLARE
e_name Employees.name%type;
e_code Employees.code%type;
e_doj Employees.doj%type;
e_salary Employees.salary%type;
e_dop Employees.dop%type;
BEGIN
e_name="saurabh";
e_code=3;
e_doj=TO_DATE('9/5/2020','DD/MM/YYYY');
e_salary=40000;
e_dop=TO_DATE('9/5/2020','DD/MM/YYYY');
BEGIN
==========================================
Ques- 2 > wap to calculate the total salary give to the employee to the current
year using cursor,also use exception.
DECLARE
e_salary Employees.salary%type;
p_da pay.da%type;
p_hra pay.hra%type;
total_salary number(10);
Calculate_Salary varchar2(1000);
CURSOR Calculate_salary IS
BEGIN
BEGIN
Calculate_Salary:='
create table Employee_Salary
(
e_salary number(5),
p_da real(5,2),
p_hra real(5,2),
total_salary real(10,2),
)';
execute immediate Calculate_Salary;
commit;
END;
OPEN Calculate_salary;
LOOP
EXCEPTION
WHEN Calculate_salary%notfound THEN
dbms_output.put_line('No more records');
total_salary=e_salary+p_da+p_hra;
dbms_output.put_line(total_salary);
BEGIN
execute immediate INSERT INTO Employee_Salary VALUES(e_salary, p_da, p_hra,
total_salary);
END;
close LOOP;
close Calculate_salary;
END;
==========================================
Ques-3> wap to count that how many employees are in the employees table using
cursor, also use exception.
DECLARE
total_Employee Number(3);
CURSOR Employee IS
select * from Employees;
BEGIN
OPEN Employee;
EXCEPTION
WHEN sql%notfound THEN
dbms_output.put_line("record finished");
total_Employee= Employee%ROWCOUNT;
dbms_output.put_line("Total_Employees"||total_Employee);
CLOSE Employee;
END;