0% found this document useful (0 votes)
101 views5 pages

PLSQL Program For Beginner and Dummies

The document describes a PL/SQL program that generates the Fibonacci series. It declares variables to store the numbers in the series, initializes the first two numbers to 0 and 1, and then uses a for loop to calculate each subsequent number by adding the previous two and outputting it. The output shows the program generating the first 3 numbers of the Fibonacci series when run with an input of 3.
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)
101 views5 pages

PLSQL Program For Beginner and Dummies

The document describes a PL/SQL program that generates the Fibonacci series. It declares variables to store the numbers in the series, initializes the first two numbers to 0 and 1, and then uses a for loop to calculate each subsequent number by adding the previous two and outputting it. The output shows the program generating the first 3 numbers of the Fibonacci series when run with an input of 3.
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/ 5

PL/SQL PROGRAM TO PRINT FIBONACCI SERIES

Write a PL/ SQL program to generate Fibonacci series


declare
a number;
b number;
c number;
n number;
i number;
begin
n:=&n;
a:=0;
b:=1;
dbms_output.put_line(a);
dbms_output.put_line(b);
for i in 1..n-2
loop
c:=a+b;
dbms_output.put_line(c);

a:=b;
b:=c;
end loop;
end;
/
OUTPUT:
SQL> @ FIBONACCI.sql
Enter value for n: 3
old 8: n:=&n;
new 8: n:=3;
0
1
1
PL/SQL procedure successfully completed.

Answer :

SET SERVEROUTPUT ON
DECLARE
num number(3);
s1 number(3);
s2 number(3);

s3 number(3);
BEGIN
s1:=0;
s2:=1;
s3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(s3);
s1 := s2;
s2 := s3;
s3:=s1+s2;
num:=num+1;
end loop;
END;

Q) Write a PL/SQL Program to display the number in Reverse Order

declare
a number;
rev number;
d number;
begin
a:=&a;

rev:=0;
while a>0
loop
d:=mod(a,10);
rev:=(rev*10)+d;
a:=trunc(a/10);
end loop;
dbms_output.put_line('Reverse of no is'|| rev);
end;
/

OUTPUT:

SQL> @ REVERSE2.sql
Enter value for a: 536
old 6: a:=&a;
new 6: a:=536;
Reverse of no is 635

PL/SQL procedure successfully completed.

You might also like