0% found this document useful (0 votes)
24 views6 pages

Exp 5

Uploaded by

optimustitans7
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)
24 views6 pages

Exp 5

Uploaded by

optimustitans7
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/ 6

# Program for employee salary (da,hra,pf,basic)

SQL> set serveroutput on


SQL> declare
2 enamevarchar(90);
3 basic number;
4 da number;
5 hra number;
6 pf number;
7 netsalary number;
8 yearsalary number;
9 begin
10 ename:='Sudarshan';
11 basic:=100000;
12 da:=basic*(30/100);
13 hra:=basic*(10/100);
14 if(basic<50000)
15 then
16 pf:=basic*(8/100);
17 elsif(basic>=50000 and basic<=120000)
18 then
19 pf:=basic*(10/100);
20 end if;
21 netsalary:=basic+da+hra-pf;
22 yearsalary:=netsalary*12;
23 dbms_output.put_line('Employee name :'||ename);
24 dbms_output.put_line('providend fund:'||pf);
25 dbms_output.put_line('Net salary :'||netsalary);
26 dbms_output.put_line('year salary :'||yearsalary);
27 end;
28 /
Output:
Employee name :Sudarshan
providend fund:10000
Net salary :130000
year salary :1560000
PL/SQL procedure successfully completed.

C SUDARSHAN 22F41A0520 CSE-A


# Program for accept year sal of a employee
SQL> declare
2 ename varchar(900);
3 basic number;
4 da number;
5 hra number;
6 pf number;
7 netsalary number;
8 yearsalary number;
9 begin
10 ename:='Kanna';
11 basic:=100000;
12 da:=basic*(30/100);
13 hra:=basic*(10/100);
14 if(basic<50000)
15 then
16 pf:=basic*(8/100);
17 elsif(basic>=50000 and basic<=120000)
18 then
19 pf:=basic*(10/100);
20 end if;
21 netsalary:=basic+da+hra-pf;
22 yearsalary:=netsalary*12;
23 dbms_output.put_line('employee name:'||ename);
24 dbms_output.put_line('providend fund:'||pf);
25 dbms_output.put_line('net salary :'||netsalary);
26 dbms_output.put_line('year salary:'||yearsalary);
27 end;
28 /
OUTPUT:
employeename:Kanna
providend fund:10000
net salary :130000
year salary:1560000

PL/SQL procedure successfully completed.

C SUDARSHAN 22F41A0520 CSE-A


# Program for creating function for factorial of a number
SQL> create or replace function fact(n number)
2 return number is
3 a number:=n;
4 f number:=1;
5 i number;
6 begin
7 fori in 1..n
8 loop
9 f:=f*a;
10 a:=a-1;
11 end loop;
12 return f;
13 end;
14 /
Function created.
SQL> create or replace function ncr(n number,r number)
2 return number is
3 n1 number:=fact(n);
4 r1 number:=fact(r);
5 nr1 number:=fact(n-r);
6 result number;
7 begin
8 result:=(n1)/(r1*nr1);
9 return result;
10 end;
11 /
OUTPUT:

Function created.

C SUDARSHAN 22F41A0520 CSE-A


# Program for prime fibonacii series

SQL> create or replace function fib(n positive)return integer is

2 begin

3 if(n=1) or (n=2) then --terminating condition

4 return 1;

5 else

6 return fib(n-1)+fib(n-2); --recursive call

7 end if;

8 end fib;

9 /

OUTPUT:

Function created.

SQL> --test fibonacii series;

SQL> select fib(1),fib(2),fib(3),fib(4),fib(5),fib(6) from dual;

FIB(1) FIB(2) FIB(3) FIB(4) FIB(5) FIB(6)

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

1 1 2 3 5 8

# Program for finding lucky number by giving birth date

C SUDARSHAN 22F41A0520 CSE-A


SQL> set serveroutput on
SQL> declare
2 l_input varchar(90):='31/10/2005';
3 l_outputint;
4 begin
5 loop
6 dbms_output.put_line('l_input :'||l_input);
7 l_output:=0;
8 fori in 1..length(l_input)
9 loop
10 ifsubstr(l_input,i,1) between '0' and '9' then
11 l_output:=l_output+to_number(substr(l_input,i,1));
12 end if;
13 end loop;
14 dbms_output.put_line('l_output :'||l_output);
15 exit when l_output<10;
16 l_input:=to_char(l_output);
17 end loop;
18 dbms_output.put_line('------------------------------');
19 dbms_output.put_line('lucky number is:'||l_output);
20 end;
21 /
OUTPUT:

l_input :31/10/2005

l_output :12
l_input :12
l_output :3
------------------------------
lucky number is:3
PL/SQL procedure successfully completed.

# Program for finding reverse of a number

C SUDARSHAN 22F41A0520 CSE-A


SQL> set serveroutput on

SQL> declare

2 num number;

3 rev number;

4 begin

5num:=2345;

6 rev:=0;

7 while num> 0 loop

8 rev:=(rev*10)+mod(num,10);

9 num:=floor(num/10);

10 end loop;

11dbms_output.put_line('Reverse of a number is:'||rev);

12 end;

13 /

OUTPUT:

Reverse of a number is:5432

PL/SQL procedure successfully completed.

C SUDARSHAN 22F41A0520 CSE-A

You might also like