Showing posts with label plsql program. Show all posts
Showing posts with label plsql program. Show all posts

Friday, December 16, 2011

PL/SQL Sample Examples

Hello Friends, here discuss some sample examples related to PL/SQL programming language. These all are basic example to understand PL/SQL syntax.
I used oracle 10g during program development. There are program to understand declare statement, loop concept, procedure, function, exception handling, cursor etc.


PL/SQL Sample Examples List

1. PL/SQL Example to find average of three numbers

2. PLSQL Example Find Even Odd Number

3. PL/SQL program to generate Fibonacci series

4. Check Number is Armstrong in PL/SQL Programming

5. PL/SQL Program to reverse a string

6. Basic LOOP Program in PL/SQL

7. PLSQL FOR Loop Example

8. Reverse a Number in PL/SQL Programming

9. PL/SQL Procedure Sample Example

10. Function Example in PL/SQL Oracle

11. Exception Handling Program in PL/SQL Oracle

Hope, these sample programs help you to understand PL/SQL programming language.

Thursday, November 17, 2011

Basic LOOP Program in PL/SQL

It is a PL/SQL program which show how to use basic loop concept in PL/SQL block.

Aim - PL/SQL program to print 1 to 10 using basic loop.


Sample Program: -
declare
  num number(3);
begin
  num:=1;
  loop
     dbms_output.put_line(num);
     num:=num+1;
     exit when num>10;  
  end loop;
end;

Output: -
1
2
3
4
5
6
7
8
9
10

Saturday, November 12, 2011

PL/SQL Example to find average of three numbers

This is a PL/SQL sample example to accept three numbers from the user and find average of accepted numbers.

Aim - PL/SQL Example to find average of three numbers



Sample Program : -


declare
a number(3);
b number(3);
c number(3);
avgr number(5,2);
begin
a:=&a;
b:=&b;
c:=&c;
avgr:=((a+b+c)/3);
dbms_output.put_line('Average of a, b, c is: '||avgr);
end;


Output of PL SQL Block: -

Enter value for a: 22
old 7: a:=&a;
new 7: a:=22;
Enter value for b: 32
old 8: b:=&b;
new 8: b:=32;
Enter value for c: 43
old 9: c:=&c;
new 9: c:=43;
Average of a, b, c is: 32.33

PL/SQL program to generate Fibonacci series

It is a sample example of generate fibonacci series upto 10 numbers.

Aim - PL/SQL program to generate Fibonacci series.



PLSQL Sample Program: -

declare
f1 number(3);
f2 number(3);
f3 number(3);
num number(3);
begin
f1:=0;
f2:=1;
f3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(f3);
f1 :=f2;
f2:=f3;
f3:=f1+f2;
num:=num+1;
end loop;
end;




Output of PL SQL Block: -
0
1
1
2
3
5
8
13
21
34