0% found this document useful (0 votes)
65 views59 pages

Client Server Lab

1. The document contains programs written in PL/SQL to demonstrate various concepts like finding odd or even numbers, checking prime numbers, calculating factorials, generating Fibonacci series, checking Armstrong and perfect numbers, using cursors, creating packages, and handling exceptions. 2. The programs take user input, perform the required logic, and display the output. Sample outputs are provided for each program showing successful execution and results. 3. In conclusion, the programs were able to successfully execute the given logic and produce the expected output, verifying the concepts demonstrated.

Uploaded by

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

Client Server Lab

1. The document contains programs written in PL/SQL to demonstrate various concepts like finding odd or even numbers, checking prime numbers, calculating factorials, generating Fibonacci series, checking Armstrong and perfect numbers, using cursors, creating packages, and handling exceptions. 2. The programs take user input, perform the required logic, and display the output. Sample outputs are provided for each program showing successful execution and results. 3. In conclusion, the programs were able to successfully execute the given logic and produce the expected output, verifying the concepts demonstrated.

Uploaded by

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

1.

ODD OR EVEN

AIM:
To write a PL/SQL program to find odd or even between numbers.

PROGRAM:

declare
n number(5);
a number(5):=&a;
begin
n:=mod(a,2);
if (n=0)then
dbms_output.put_line('the number is even');
else
dbms_output.put_line('the number is odd');
end if;
end;
OUTPUT:

SQL> set serveroutput on


SQL> ed oddeven.sql;

SQL> @ oddeven.sql;
12 /
Enter value for a: 7
old 3: a number(5):=&a;
new 3: a number(5):=7;
the number is odd
PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
2. PRIME NUMBER

AIM:
To write a PL/SQL program to illustrate prime numbers.

PROGRAM:

declare
n number(5);
p number(5);
c number(5)
r number(5);
i number(5);
begin
p :=0;
c:=n;
n:=&n;
for i in 2..n loop
r := n mod i;
if(r=0) then
p:=p+1;
end if;
end loop;
if(p=1) then
dbms_output.put_line(c||'the no is prime');
else
dbms_output.put_line(c||'the no is not prime');
end if;
end;
OUTPUT:

SQL> set serveroutput on


SQL> ed prime.sql;
SQL> @ prime.sql;
Enter value for n: 7
old 10: n:=&n;
new 10: n:=7;
the no is prime
PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
3. FACTORIAL VALUE
AIM:
To write a PL/SQL program to illustrate factorial value.

PROGRAM:

declare
n number(10):=&n;
i number(10);
f number(10):=1;
begin
if(n=0) then
f:=1;
else
for i in 1..n loop
f:=f*i;
end loop;
end if;
dbms_output.put_line(n||'factorial is '||f);
end;
OUTPUT:

SQL> set serveroutput on


SQL> ed fact.sql;
SQL> @ fact.sql;
15 /
Enter value for n: 5
old 2: n number(10):=&n;
new 2: n number(10):=5;
5factorial is 120
PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
4. FIBONACCI SERIES

AIM:
To write a PL/SQL program to illustrate Fibonacci series for a number.

PROGRAM:

declare
n number(5):=&n;
a number(5);
b number(5);
c number(10);
i number(10);
begin
a:=-1;
b:=1;
for i in 1..n loop
c:=a+b;
dbms_output.put_line(c);
a:=b;
b:=c;
end loop;
end;
OUTPUT:

SQL> set serveroutput on


SQL> ed fibo.sql;

SQL> @ fibo.sql;
17 /
Enter value for n: 2
old 2: n number(10):=&n;
new 2: n number(10):=2;
0
1
PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
5. ARMSTRONG NUMBER

AIM:
To write a PL/SQL program to check amstrong number or not.

PROGRAM:

declare
n number(10):=&n;
r number(10);
s number(10):=0;
t number(10);
begin
t:=n;
while(n!=0) loop
r:=mod(n,10);
s:=s+r*r*r;
n:=floor(n/10);
end loop;
if(t=s) then
dbms_output.put_line(s||' amsrong:'||s);
else
dbms_output.put_line(s||' not amsrong:'||s);
end if;
end;
OUTPUT:

SQL> set serveroutput on


SQL> ed am.sql;

SQL> @ am.sql;
19 /
Enter value for n: 153
old 2: n number(10):=&n;
new 2: n number(10):=153;
153 amsrong:153

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
6. SUM OF DIGITS

AIM:
To write a PL/SQL program to find sum for given set of numbers.

PROGRAM:

declare
n number(10):=&n;
r number(10);
s number(10):=0;
begin
while(n>0) loop
r:=mod(n,10);
s:=s+r;
n:=floor(n/10);
end loop;
dbms_output.put_line('sum of digits is :'||s);
end ;
OUTPUT:

SQL> set serveroutput on


SQL> ed sum.sql;

SQL> @ sum.sql;
13 /
Enter value for n: 153
old 2: n number(10):=&n;
new 2: n number(10):=153;
sum of digits is :9

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
7. PERFECT NUMBER

AIM:
To write a PL/SQL program to find the number is perfect or not.

PROGRAM:

declare
a number(5):=&a;
b number(5);
c number(5):=0;
i number(5);
begin
for i in 1..a-1 loop
b:=mod(a,i);
if(b=0)then
c:=(c+i);
end if;
end loop;
if(a=c)then
dbms_output.put_line('perfect number');
else
dbms_output.put_line('not perfect number');
end if;
end ;
OUTPUT:

SQL> set serveroutput on


SQL> ed perfect.sql;

SQL> @ perfect.sql;
19 /
Enter value for a: 6
old 2: a number(5):=&a;
new 2: a number(5):=6;
perfect number

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
8. CURSOR USING EXPLICIT

AIM:
To write a PL/SQL program to illustrate explicit cursor.

TABLE CREATION:

SQL> create table studd1(name varchar(22),m1 number(5),m2 number(5),m3 number(5));


Table created.
SQL> insert into studd1 values('kkkk',78,90,58);
1 row created.
SQL> insert into studd1 values('ssss',89,56,90);
1 row created.
SQL> create table studd2(total number(8),result varchar(20));
Table created.

PROGRAM:
declare
cursor cstudd1 is select * from studd1;
studd2 studd1%rowtype;
total number(5);
result varchar2(10);
begin
open cstudd1;
dbms_output.put_line('name'||' '||'total'||' '||'result');
dbms_output.put_line('*********************************************');
loop
fetch cstudd1 into studd2;
exit when cstudd1%notfound;
total:=studd2.m1+studd2.m2+studd2.m3;
if(studd2.m1>=35 and studd2.m2>=35 and studd2.m3>=35)then
result:='pass';
else
result:='fail';
end if;
dbms_output.put_line(studd2.name||' '||total||' '||result);
end loop;
close cstudd1;
commit;
end;
OUTPUT:

SQL> set serveroutput on


SQL> ed explict.sql;
SQL> @ explict.sql;
name total result
*********************************************
kkkk 226 pass
ssss 235 pass
pppp 168 fail

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
9. CURSOR USING IMPLICIT

AIM:
To write a PL/SQL program to illustrate implicit cursor.

TABLE CREATION:

SQL> create table studd1(rno number(10),name varchar(22),m1 number(5),m2 number(5),m3


number(5));
Table created.
SQL> insert into studd1 values(1,'kkkk',78,90,58);
1 row created.
SQL> insert into studd1 values(2,'ssss',89,56,90);
1 row created.
SQL> insert into studd1 values(3,'pppp',89,59,20);
1 row created.
SQL> alter table studd1 add(tot number(5));
Table altered.
SQL> update studd1 set tot=m1+m2+m3;
3 rows updated.

PROGRAM:

declare
cursor cstudd1 is select * from studd1;
studd2 studd1%rowtype;
total number(15);
begin
update studd1 set total=total+100 where rno=&rno;
if sql%notfound then
dbms_output.put_line('student does not exit');
else
dbms_output.put_line('student record modified succesfully');
end if;
end;
OUTPUT:

SQL> ed implicit

SQL> @ implicit.sql;
13 /
Enter value for rno: 1
old 6: update studd1 set tot=tot+100 where rno=&rno;
new 6: update studd1 set tot=tot+100 where rno=1;
student record modified succesfully

PL/SQL procedure successfully completed.

SQL> select * from studd1;

RNO NAME M1 M2 M3 TOT


---------- ---------------------- ---------- ---------- ---------- ----------
1 kkkk 78 90 58 326
2 ssss 89 56 90 235
3 pppp 89 59 20 168

RESULT:
Thus the above program executed successfully and the output was verified.
10. PACKAGE

AIM:
To write a PL/SQL program to illustrate package creation and to do various arithmetic
operations.

PROGRAM:

PACKAGE CREATION:
create or replace package calc is procedure padd(a number,b number);
procedure psub(a number,b number);
procedure pmul(a number,b number);
procedure pdiv(a number,b number);
procedure pmod(a number,b number);
procedure psqrt(a number);
end;
/

PACKAGE BODY CREATION:


create or replace package body calc is
procedure padd(a number,b number)is c number;
begin
c:=a+b;
dbms_output.put_line('addition:'||c);
end padd;
procedure psub(a number,b number)is c number;
begin
c:=a-b;
dbms_output.put_line('subraction:'||c);
end psub;
procedure pmul(a number,b number)is c number;
begin
c:=a*b;
dbms_output.put_line('multiplication:'||c);
end pmul;
procedure pdiv(a number,b number)is c number;
begin
c:=a/b;
dbms_output.put_line('division:'||c);
end pdiv;
procedure pmod(a number,b number)is c number;
begin
c:=mod(a,b);
dbms_output.put_line('madulo division:'||c);
end pmod;
procedure psqrt(a number)is c number;
begin
c:=sqrt(a);
dbms_output.put_line('square root:'||c);
end psqrt;
end calc;
/
OUTPUT:
SQL> set serveroutput on
SQL> ed calc.sql;

SQL> @ calc.sql;
Input truncated to 1 characters

Package created.

SQL> ed packagebody.sql;

SQL> @ packagebody.sql;

Package body created.

SQL> exec calc.padd(5,5)


addition:10

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
11. COMMISSION USER EXCEPTION

AIM:
To write a PL/SQL program to check whether the commission is enough or not.

PROGRAM:

TABLE CREATION:
SQL> create table emp2(eno number(20),sal number(20),commission number(20));
Table created.
SQL> insert into emp2 values(1,4000,700);
1 row created.
SQL> insert into emp2 values(2,7000,200);
1 row created.

CODING:
declare
app_err exception;
n varchar2(14);
e emp2%rowtype;
nsal number(10);
begin
n:=&n;
select * into e from emp2 where eno=n;
nsal:=e.sal+e.commission;
if(e.commission>300)then
dbms_output.put_line('Net salary'||nsal);
else
raise app_err;
end if;
exception
when app_err then
dbms_output.put_line('Commission is not enough');
end;
/
OUTPUT:

SQL> set serveroutput on


SQL> @ excep5.sql;
Enter value for n: 2
old 7: n:=&n;
new 7: n:=2;
Commission is not enough

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
12. NO DATA FOUND EXCEPTION

AIM:
To write a PL/SQL program to illustrate the function no data found.

PROGRAM:

TABLE CREATION:
SQL> create table list(name varchar(20),reno number(5));
Table created.
SQL> insert into list values('rrr',24);
1 row created.

CODING:
declare
name list.name%type;
reno list.reno%type;
n number(3);
begin
n:=&n;
select name,reno into name,reno from list where reno=n;
dbms_output.put_line('name:'||name);
dbms_output.put_line('reno:'||reno);
exception
when no_data_found then
dbms_output.put_line('Record not found');
end;
/
OUTPUT:

SQL> @ excep4.sql;
Enter value for n: 22
old 6: n:=&n;
new 6: n:=22;
Record not found

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
13. ZERO DIVIDE ERROR

AIM:
To write a PL/SQL program to illustrate the exception for dividing value by zero.

PROGRAM:

declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=a/b;
dbms_output.put_line('c='||c);
exception
when zero_divide then
dbms_output.put_line('divide is equal to zero');
end;
/
OUTPUT:

SQL> set serveroutput on


SQL> ed excep3.sql;
SQL> @ excep3.sql;
Enter value for a: 4
old 6: a:=&a;
new 6: a:=4;
Enter value for b: 0
old 7: b:=&b;
new 7: b:=0;
divide is equal to zero

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
14. PROCEDURE INOUT PARAMETER

AIM:
To write a PL/SQL program to illustrate inout parameter using procedure.

PROGRAM:

PROCEDURE CREATION:
create or replace procedure palind(a in varchar,b in out varchar,c in out varchar) is
k int;
i int;
m varchar(20);
d varchar(20);
begin
k := length(a);
for i in reverse 1..k loop
m:= substr(a,i,1);
d:= d||m;
end loop;
if(d=a)then
c:=c||'yes';
b:=d;
end if;
end;
/

CODING:
declare
a varchar(40);
b varchar(40);
c varchar(40);
begin
a:='&a';
c:='given string is palindrome';
palind(a , b , c);
dbms_output.put_line('palindrome is'||b);
dbms_output.put_line(c);
end;
/
OUTPUT:
SQL> set serveroutput on
SQL> ed palind.sql;
SQL> @ palind.sql;
Input truncated to 1 characters
Procedure created.

SQL> @ palindr.sql;
Enter value for a: madam
old 6: a:='&a';
new 6: a:='madam';
palindrome is madam
given string is palindrome yes

PL/SQL procedure successfully completed.

RESULT:
Thus the above program executed successfully and the output was verified.
15. TRIGGER

AIM:
To write a PL/SQL program to illustrate trigger.

PROGRAM:

create or replace trigger ks before delete on sud for each row begin
insert into sud1 values(:old.eno,:old.name,:old.sal);
end;
/
OUTPUT:
SQL> set serveroutput on
SQL> ed trig.sql;

SQL> @ trig.sql;
Input truncated to 1 characters

Trigger created.
SQL> delete from sud where eno=2;

1 row deleted.
SQL> select * from sud;

ENO NAME SAL


---------- -------------------- ----------
1 karthi 10000

SQL> select * from sud1;

ENO NAME SAL


---------- -------------------- ----------
2 sakthi 15000

RESULT:
Thus the above program executed successfully and the output was verified.
16. INVENTORY DETAILS

AIM:
To create form and report builder using inventory details.

TABLE CREATION:

SQL> create table invent(cname char(22),addr char(22),pro char(22),pri number(22),quan


number(22),tot number(22));

Table created.

FORM DESIGN:
CODING:

Insert :
begin
go_item('invent.cname');
:global.v:=1;
clear_record;
end;

Calculate:
begin
:invent.tot:=:invent.pri*:invent.quan;
end;

Save:
begin
clear_form(do_commit);
end;

Update:
begin
update invent set
cname=invent.cname,addr=invent.addr,pro=invent.pro,pri=invent.pri,quan=invent.quan,tot=inve
nt.tot where cname=invent.cname;
clear_form(do_commit);
commit;
end;

Display:
begin
execute_query;
end;
OUTPUT:
REPORT:

RESULT:
Thus the above program executed successfully and the output was verified.
17. BANKING DETAILS

AIM:
To create form and report builder using bank details.

TABLE CREATION:

SQL> create table bank(name varchar2(20),acno number(6),opamt number(6),deposit


number(6),withdraw number(6),balance number(6));

Table created.

FORM DESIGN:
CODING:

Insert:
begin
go_item(':bank2.name');
:global.v:=1;
clear_record;
end;

Update:
begin
update bank2 set
name=bank2.name,acno=bank2.acno,opamt=:bank2.opamt,deposit=bank2.deposit,withdraw=ban
k2.withdraw,balance=bank2.balance where name=bank2.name;
clear_form(do_commit);
commit;
end;

Calculate:
begin
:bank2.balance:=:bank2.balance+:bank2.deposit;
:bank2.balance:=:bank2.balance-:bank2.withdraw;
end;

Delete:
begin
delete_record;
commit;
end;

Display:
begin
execute_query;
end;

First Record:
begin
first_record;
end;

Previous Record:
begin
previous_record;
end;

Next Record:
begin
next_record;
end;

Last Record:
begin
last_record;
end;
OUTPUT:
REPORT:

RESULT:
Thus the above program executed successfully and the output was verified.
18. STUDENT MARK LIST

AIM:
To create form and report builder for student mark list.

TABLE CREATION:

SQL> create table student(rno number(5),name varchar2(20),m1 number(3),m2


number(3),tot number(3),avg number(3));

Table created.

FORM DESIGN:
CODING:

Insert:
begin
go_item('student.rno');
:global.v:=1;
clear_record;
end;

Calculate:
begin
:student.tot:=:student.m1+:student.m2;
:student.avg:=:student.tot/2;
end;

Save:
begin
clear_form(do_commit);
end;

Delete:
begin
delete_record;
commit;
end;

Display:
begin
execute_query;
end;

Update:
begin
update student set
name=student.name,m1=student.m1,m2=student.m2,tot=student.tot,avg=student.avg where
rno=student.rno;
clear_form(do_commit);
commit;
end;

First Record:
begin
first_record;
end;

Previous Record:
begin
previous_record;
end;

Next Record:
begin
next_record;
end;

Last Record:
begin
last_record;
end;
OUTPUT:
REPORT:

RESULT:
Thus the above program executed successfully and the output was verified.
19. PAYROLL MANAGEMENT SYSTEM

AIM:
To create form and report builder using payroll management system.

TABLE CREATION:

SQL>create table pay(ename varchar2(20),eno number(5),bp number(8),hra number(5),ta


number(5),da number(5),lic number(5),pf number(5),gs number(5),ns number(5));

Table created.

FORM DESIGN:
CODING:

Insert:
begin
go_item(':pay.eno');
:global.v:=1;
clear_record;
end;

Delete:
begin
delete_record;
commit;
end;

Update:
begin
update pay set
ename=pay.ename,eno=pay.eno,hra=pay.hra,ta=pay.ta,da=pay.da,lic=pay.lic,pf=pay.pf,gs
=pay.gs,ns=pay.ns where eno=pay.eno;
clear_form(do_commit);
commit;
end;

Save:

begin
clear_form(do_commit);
end;

Display:
begin
execute_query;
end;
Calculation:
begin
:pay.hra:=:pay.bp*0.07;
:pay.ta:=:pay.bp*0.06;
:pay.da:=:pay.bp*0.03;
:pay.lic:=:pay.bp*0.01;
:pay.pf:=:pay.bp*0.02;
:pay.gs:=:pay.hra + :pay.da + :pay.ta;
:pay.ns:=:pay.gs - :pay.pf - :pay.lic;
end;

First Record:
begin
first_record;
end;

Previous Record:
begin
first_record;
end;

Next Record:
begin
first_record;
end;

Last Record:
begin
last_record;
end;
OUTPUT:
REPORT:

RESULT:
Thus the above program executed successfully and the output was verified.
20. RAILWAY RESERVATION SYSTEM

AIM:
To create form and report builder for railway reservation system.

TABLE CREATION:

SQL>create table railway(name varchar2(20),tname varchar2(20),seatno number(5),amt


number(5),contact number(10),sourse varchar2(20),destination varchar2(20));

Table created.

FORM DESIGN:
CODING:

Insert:
begin
go_item('train.name');
:global.v:=1;
clear_record;
end;

Delete:
begin
delete_record;
commit;
end;

Save:
begin
clear_form(do_commit);
end;

Display:
begin
clear_form(do_commit);
end;

First Record:
begin
first_record;
end;

Previous Record:
begin
first_record;
end;
Next Record:
begin
next_record;
end;
OUTPUT:
REPORT:

RESULT:
Thus the above program executed successfully and the output was verified.

You might also like