You are on page 1of 18

#########################################################################

# Program No
:
01
#
# Program Aim
:
Multiplication Table
#
# Author
:
Akhil P George
#
# Date
:
29/01/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read n, limit
3: Set i=1
4: Print i*n
5: i++
6: If i != limit+1go to step 4
7: End
PLSQL CODE BLOCK
declare
i number;
n number;
lim number;
begin
n:=&n;
lim:=&lim;
i:=1;
while(lim>0)loop
dbms_output.put_line(n||'*'||i||'='||n*i);
i:=i+1;
lim:=lim-1;
end loop;
end;
/

OUTPUT
Enter value for n: 5
Enter value for lim: 10
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50

RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
02
#
# Program Aim
:
Reverse a number
#
# Author
:
Akhil P George
#
# Date
:
29/01/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read n
3: Initialize r=0,s=0 and c=10
4: Repeat through step7 while (n>0)
5: r=n mod 10
6: s=r+s*c
7: n=floor(n/10)
8: Print s
9: End
PLSQL CODE BLOCK
declare
n number;
r number;
c number;
d number;
s number;
begin
n:=&n;
r:=0;
s:=0;
c:=10;
d:=n;
while(n>0)loop
r:=n mod 10;
s:=r+s*c;
n:=floor(n/10);
end loop;
dbms_output.put_line('The reverse of'||d||'is'||s);
end;
/
OUTPUT
Enter value for n: 234
The reverse of 234 is 432
RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
03
#
# Program Aim
:
Fibonacci Series
#
# Author
:
Akhil P George
#
# Date
:
29/01/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read n
3: Intialize i=0 and j=1
4: Print i and j
5: n=n-2
6: Repeat through step 10 while n>0
7: k=i+j
8: i=j and j=k
9: Print k
10: Decrement n
11: End
PLSQL CODE BLOCK
declare
n number;
i number;
j number;
k number;
begin
n:=&n;
i:=0;
j:=1;
dbms_output.put_line(i);
dbms_output.put_line(j);
n:=n-2;
while(n>0)loop
k:=i+j;
i:=j;
j:=k;
dbms_output.put_line(k);
n:=n-1;
end loop;
end;
/

OUTPUT
Enter value for n: 5
0
1
1
2
3
RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
04
#
# Program Aim
:
Conversion of number system
#
# Author
:
Akhil P George
#
# Date
:
03/02/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read num
3: n = num
4: I = n mod 2
5: append I before s
6: n = n/2
7: if n > 0 go to step 4 else print s
8: n = num, s = NULL
9: I = n % 16
10: if I=10 append A before s else
11: if I=11 append B before s else
12: if I=12 append C before s else
13: if I=13 append D before s else
14: if I=14 append E before s else
15: if I=15 append F before s else
16: else append I before s
17: n = n/16
18: if n>0 go to step 9 else print s
19: n = num
20: I = n mod 8
21: append I before s
22: n = n/8
23: if n>0 go to step 20
24: End
PLSQL CODE BLOCK
declare
n number;
num number;
i number;
svarchar(20);
s2varchar(20);
resultsvarchar(20);
begin
num:=#
i:=0;
n:=num;

while(n>0)loop
i:= n mod 2;
results:=i||results;
n:=floor(n/2);
end loop;
dbms_output.put_line('Binary value is '||results);
n:=num;
while(n>0)loop
i:=n mod 16;
case i
when 10 then s:='A'||s;
when 11 then s:='B'||s;
when 12 then s:='c'||s;
when 13 then s:='D'||s;
when 14 then s:='E'||s;
when 15 then s:='F'||s;
else s:=i||s;
end case;
n:=floor(n/16);
end loop;
dbms_output.put_line('Hex value is '||s);
n:=num;
while(n>0)loop
i:=n mod 8;
s2:=i||s2;
n:=floor(n/8);
end loop;
dbms_output.put_line('Octal value is '||s2);
end;
/
OUTPUT
Enter value for num: 456
Binary value is 111001000
Hex value is 1c8
Octal value is 710
RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
05
#
# Program Aim
:
Retrieve employee data
#
# Author
:
Akhil P George
#
# Date
:
09/03/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read no
3: Select records from employee where no matches with employee number
4: Select records from works where no matches with employee number
5: Print Empname, Join, Designation
6: End
PLSQL CODE BLOCK
declare
emp_no emp06.emp_no%type;
ename emp06.emp_name%type;
jdate works06.join_date%type;
desig works06.designation%type;
begin
emp_no:=&emp_no;
select emp_name INTO ename from emp06 where emp06.emp_no=emp_no;
dbms_output.put_line('Employee Name'|| ename);
select join_date,designation INTO jdate,desig from works06
where works06.emp_no=emp_no;
dbms_output.put_line('Joining Date' || jdate);
dbms_output.put_line('Designation' || desig);
end;
/
OUTPUT
Enter the value for emp_no
Employee Name
Joining Date
Designation

:
:
:
:

100
Raju
25-feb-15
Programmer

RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
06
#
# Program Aim
:
Calculate tax
#
# Author
:
Akhil P George
#
# Date
:
09/03/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read employee no
3: Select Employee no from employee where no matches with empname
4: Select salary from works where empno matches with employee number
5: Set threshold=100000
6: Read DA, HRA, Deduction
7: sal-per_yr=net_sal*12
8: If sal_per_yr>threshold then diff=sal_per_yr threshold, tax=diff*0.5
9: Print Employee Name, net salary,salary per year,tax
10: End
PLSQL CODE BLOCK
declare
emp_no emp06.emp_no%type;
name emp06.emp_name%type;
net_sal emp_salary06.net_salary%type;
sal_per_yr number;
diff number;
tax number;
threshold number;
begin
emp_no:=&emp_no;
select emp_name INTO name from emp06 where emp06.emp_no=emp_no;
dbms_output.put_line('Name is :'||name);
select net_salary INTO net_sal from emp_salary06
where emp_salary06.emp_no=emp_no;
dbms_output.put_line('Net salary is :'||net_sal);
threshold:=100000;
sal_per_yr:=net_sal*12;
dbms_output.put_line('salary per year is :'||sal_per_yr);
dbms_output.put_line('Threshold value is :'||threshold);
if(sal_per_yr>threshold)then
dbms_output.put_line('Tax: ');
diff:=sal_per_yr-threshold;
tax:=diff*(5/100);

dbms_output.put_line(tax);
else
dbms_output.put_line('Employee does not pay any tax');
end if;
end;
/
OUTPUT
Enter value for emp_no
Name is
Net salary is
salary per year is
Threshold value is
Tax

: 102
: Shehin
: 30000
: 360000
: 100000
: 13000

RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
07
#
# Program Aim
:
Update Salary Table
#
# Author
:
Akhil P George
#
# Date
:
11/03/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read empno
3: Update entries of empsalary with
DA=Basic * .50, GROSS=BASIC+HRA+DA,
NET=GROSS-Deduction for all records where Employee no matches with empno
4: End
PLSQL CODE BLOCK
declare
emp_no emp06.emp_no%type;
net_sal emp_salary06.net_salary%type;
bas emp_salary06.basic%type;
new_da emp_salary06.da%type;
d emp_salary06.da%type;
gross emp_salary06.gross_salary%type;
hr emp_salary06.hra%type;
deduction emp_salary06.total_ded%type;
begin
emp_no:=&emp_no;
select basic,hra,da,total_ded,gross_salary into bas,hr,d,deduction,gross
from emp_salary06 where emp_no=emp_no;
dbms_output.put_line('Basic salary is :'||bas);
dbms_output.put_line('HRA is :'||hr);
dbms_output.put_line('Total deduction is :'||deduction);
dbms_output.put_line('gross salary is :'||gross);
new_da:=bas*(50/100);
update emp_salary06 set da=new_da where emp_no=emp_no;
dbms_output.put_line('NEW DA is :'||new_da);
gross:=bas+hr+d;
update emp_salary06 set gross_salary=gross where emp_no=emp_no;
dbms_output.put_line('New gross :'||gross);
net_sal:=gross-deduction;
update emp_salary06 set net_salary=net_sal where emp_no=emp_no;
dbms_output.put_line('New net salary :'||net_sal);
end;
/

OUTPUT
SQL> select *from emp_salary06;
EMP_NO BASIC

HRA DA

-----------

---------

------

----

100

20000

5000

10000

101

45000

10000 10000

102

35000

3000

132

16000

2000

TOTAL_DED NET_SALARY GROSS_SALARY


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

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

5000

25000

30000

10000

55000

65000

2000

10000

30000

40000

2000

5000

15000

20000

Enter value for emp_no


Basic salary is
HRA is
Total deduction is
gross salary is
NEW DA is
New gross
New net salary

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

:
:
:
:
:
:
:
:

132
16000
2000
5000
26000
8000
26000
21000

SQL> select *from emp_salary06;


EMP_NO BASIC

HRA DA

-----------

---------

------

----

100

20000

5000

10000

101

45000

10000 10000

102

35000

3000

132

16000

2000

TOTAL_DED NET_SALARY GROSS_SALARY


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

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

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

5000

25000

30000

10000

55000

65000

2000

10000

30000

40000

8000

5000

21000

26000

RESULT
PL/SQL procedure successfully completed

#########################################################################
# Program No
:
08
#
# Program Aim
:
Mark Calculator
#
# Author
:
Akhil P George
#
# Date
:
16/03/2016
#
#########################################################################
ALGORITHM
1: Start
2: Read rollno, m1, m2, m3, m4
3: Total = m1+m2+m3+m4
4: Percet = (Total / 400) *100
5: Print Total, Percet
6: End
PLSQL CODE BLOCK
declare
m1 number;
m2 number;
m3 number;
m4 number;
total number;
percent number;
begin
m1:=&m1;
m2:=&m2;
m3:=&m3;
m4:=&m4;
total:=m1+m2+m3+m4;
percent:=total/4;
dbms_output.put_line('Total ' ||total);
dbms_output.put_line('Percentage ' ||percent);
end;
/

OUTPUT
Enter value for m1
Enter value for m2
Enter value for m3
Enter value for m4

:
:
:
:

75
80
90
65

Total
Percentage

:
:

310
77.5

RESULT
PL/SQL procedure successfully completed

#########################################################################
#Program No
:
09
#
# Program Aim
:
Calculate And Display Mark Table
#
# Author
:
Akhil P George
#
# Date
:
17/03/2016
#
#########################################################################
ALGORITHM
1: Start
2: Open cursor a with all records of stud_mark06
3: Update stud_mark06set Total =m1+m2+m3+m4
4: Update stud_mark06set Percent = (Total / 400) *100
5: For each record in stud_mark06
6: Print rollno,total,per
7: End
PLSQL CODE BLOCK
declare
cursor a is
select rollno,s1,s2,s3,s4 from stud_mark06;
m1 stud_mark06.s1%type;
m2 stud_mark06.s2%type;
m3 stud_mark06.s3%type;
m4 stud_mark06.s4%type;
roll stud_mark06.rollno%type;
total number;
percent number;
begin
open a;
loop
fetch a into roll,m1,m2,m3,m4;
exit when a%NOTFOUND;
total:=m1+m2+m3+m4;
percent:=total/4;
update stud_mark06set tot=total where rollno=roll;
update stud_mark06set per=percent where rollno=roll;
update stud_enroll06 set total_marks=total where rollno=roll;
end loop;
commit;
close a;
end;
/

OUTPUT
SQL> select *from stud_mark06;
ROLLNO
-------------10
12
16
20
25

S1
-----68
50
60
50
60

S2
-----69
60
40
70
40

S3
-----68
50
70
60
40

RESULT
PL/SQL procedure successfully completed

S4
-----70
40
55
70
60

TOT
-------275
200
225
250
200

PER
---------68.75
50
56.25
62.5
50

#########################################################################
#Program No
:
10
#
# Program Aim
:
Details Of 3 Highest Paid Employees
#
# Author
:
Akhil P George
#
# Date
:
18/03/2016
#
#########################################################################
ALGORITHM
1: Start
2: Open cursor e with all records of emp06
3: Sort the records in empsalary in decreasing order of net_sal
3: exit when e%rowcount=3
4: For each record in emp06
5: End
PLSQL CODE BLOCK
declare
cursor e is
select emp06.emp_name,emp_salary06.emp_no,emp_salary06.net_salary
from emp_salary06 ,emp06 where emp06.emp_no=emp_salary06.emp_no
order by net_salary desc;
name emp06.emp_name%type;
net_sal emp_salary06.net_salary%type;
emp_no emp06.emp_no%type;
begin
open e;
dbms_output.put_line('Emp_no Name Net Salary ');
dbms_output.put_line('------------------------------------');
loop
fetch e into name,emp_no,net_sal;
dbms_output.put_line(emp_no||' '||name||' '|| net_sal);
exit when e%rowcount=3;
end loop;
close e;
end;
/

OUTPUT
SQL> select * from emp_salary06;
EMP_NO BASIC

HRA DA

-----------

---------

------

----

100

20000

5000

10000

101

45000

10000 10000

102

35000

3000

132

16000

2000

Emp_no
------------101
102
100

Name
-------------sajin
manu
Raju

TOTAL_DED NET_SALARY GROSS_SALARY


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

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

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

5000

25000

30000

10000

55000

65000

2000

10000

30000

40000

8000

5000

21000

26000

Net_Salary
---------------------55000
30000
25000

RESULT
PL/SQL procedure successfully completed

You might also like