0% found this document useful (0 votes)
7 views8 pages

Assignment No.6

Uploaded by

kulkaraniomkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Assignment No.6

Uploaded by

kulkaraniomkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment No.

Name : Onkar Sanjay Kulkarni Date :


Roll No : 29 Div : B
Sign : Remark :

-------------------------------------------------------------------------------------------------------------

Q.1. Write PL/SQL Block to calculate factorial of entered number using


function.

Create or replace function factorial(n in int)


return int is
fact int:=1 ;
Begin
for i in 1..n
loop
fact:=fact*i;
end loop;
return fact;
End;
Declare
x int;
y int;
Begin
x:=:x;
y:=factorial(x);
dbms_output.put_line('factorial ='||y);
end;
Q.2. Consider table Prod_master . Create a trigger on Prod_master
table to maintain price of product always greater than zero.

Create or Replace trigger T1


Before insert or update on Prod_master
For each row
Declare
Begin
If :new.Price<0 then
Raise_application_error(-20899,'Price should Greater than 0');
End if;
End;
Q.3. Create a explicit cursor on Employees_salary_detail table to accept
such Employee_id whose salary is in range 50000 to 100000 and update
salary of those employee by 5% of their Basic salary.

Declare
Cursor Emp is Select Employee_id,basic_salary from Employees_salary_detail
Where basic_salary between 50000 and 100000;
E1 Emp%rowtype;
Begin
Open Emp;
loop
Fetch Emp into E1;
exit when Emp%notfound;
E1.basic_salary:= E1.basic_salary+(E1.basic_salary*0.05) ;
Update Employees_salary_detail Set basic_salary= E1.basic_salary where
Employee_id=E1.Employee_id;
End loop;
Close Emp;
End;
Before update :

After update :
Q.4. create a procedure to calculate net salary of employee as follows
Net salary = Basic salary + HRA + DA
Take basic salary value from user and condition are
i)If Basic salary = 12000 then HRA = 30% and DA = 12% of Basic salary.
ii)If 12000 <Basic salary 30000 then HRA = 40% and DA = 10% of Basic
salary.
iii)If Basic salary >30000 then HRA = 50% and DA = 13% of Basic salary.

Create or replace procedure calculate_net_salary(B_sal in int , Net_sal out int) is


HRA int;
DA int ;
Begin
If B_sal=12000 then
HRA:=B_sal*0.3 ;
DA:=B_sal*0.12 ;
elsif B_sal>12000 and B_sal<30000 then
HRA:=B_sal*0.4 ;
DA:=B_sal*0.1 ;
elsif B_sal>30000 then
HRA:=B_sal*0.5 ;
DA:=B_sal*0.13 ;
end if;
Net_sal:=B_sal+HRA+DA;
End calculate_net_salary;
Declare
Basic_salary int ;
Gross_salary int ;
Begin
Basic_salary :=:Basic_salary ;
calculate_net_salary(Basic_salary ,Gross_salary);
dbms_output.put_line('Net salary of Employee is '||Gross_salary );
End ;

1}
2}

3}

You might also like