Client Server Lab
Client Server Lab
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> @ 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:
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:
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> @ 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> @ am.sql;
19 /
Enter value for n: 153
old 2: n number(10):=&n;
new 2: n number(10):=153;
153 amsrong:153
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> @ 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
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> @ perfect.sql;
19 /
Enter value for a: 6
old 2: a number(5):=&a;
new 2: a number(5):=6;
perfect number
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:
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:
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:
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
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;
/
SQL> @ calc.sql;
Input truncated to 1 characters
Package created.
SQL> ed packagebody.sql;
SQL> @ packagebody.sql;
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:
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
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:
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
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;
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:
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:
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:
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:
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:
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.