0% found this document useful (0 votes)
3 views

DBMS Lab Program-6 (1)

The document provides a series of PL/SQL programs demonstrating various control structures, including programs to check for Armstrong numbers, generate Fibonacci series, reverse a number, and calculate factorials. Each program includes code snippets, expected outputs, and instructions for execution. The aim is to illustrate the use of PL/SQL for basic mathematical operations and control flow.

Uploaded by

INDU
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)
3 views

DBMS Lab Program-6 (1)

The document provides a series of PL/SQL programs demonstrating various control structures, including programs to check for Armstrong numbers, generate Fibonacci series, reverse a number, and calculate factorials. Each program includes code snippets, expected outputs, and instructions for execution. The aim is to illustrate the use of PL/SQL for basic mathematical operations and control flow.

Uploaded by

INDU
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/ 4

PLSQL Programs

Experiment – 6
1> Save file in note pad with .sql extension ( ex: amstrong.sql )
2> To run : @ c:\folder name\filename (ex: @ c:\dbms\amstrong.sql)
( OR )
3> Type program directly in SQL+

Aim : Writing a pl/sql program using control structres


--Armstrong number

set serveroutput on;

declare

n number(10);

r number(10);

c number(10):=0;

t number(10);

begin

n:=&number;

t:=n;

while(n>0) loop

r:=mod(n,10);

c:=r*r*r+c;

n:=trunc(n/10);

end loop;

if(c=t) then

DBMS_output.put_line('it is an armstrong');

else

DBMS_output.put_line('not an armstrong');

end if;

end;

/
Output:

Enter the value for number:153

Old 7: n:=&number;

New 7: n:=153;

It is an Armstrong number PL/SQL procedure successfully completed.

--Fibonacci Series
declare

n number(2):=0;

a number(2):=0;

b number(2):=1;

begin

DBMS_output.put_line('a is'||a);

DBMS_output.put_line('b is '||b);

while(n<30) loop

DBMS_output.put_line('value is'||n);

n:=a+b;

a:=b;

b:=n;

end loop;

end;

Output: A is 0

B is 1

Value is 0

Value is 01

Value is 02

Value is 03

Value is 05

Value is 08

Value is 13
Value is 21

PL/SQL procedure successfully completed.

Aim:To find the reverse of a given number


using pl/sql program
--reverse of a given number

set serveroutput on;

declare n number(5);

r number(5):=0;

l number(5):=0;

begin

n:=&number;

while(n!=0) loop

r:=mod(n,10);

l:=l*10+r; n:=trunc(n/10);

end loop;

DBMS_output.put_line('reverse of a number is'||l);

end;

Output:

Enter the value for number:12345

Old 6: n:=&number;

New 6: n:=12345;

Reverse of a number is 54321

PL/SQL procedure successfully completed.

--Factorial of a given number


set serveroutput on;

declare

i number :=1;

f number :=1;

n number ;
begin n:=&number;

while(i<=n) loop

f:=f*i;

i:=i+1;

end loop;

DBMS_output.put_line('Factorial of a given number is' || f);

end;

Output:

Factorial is 120

PL/SQL procedure successfully completed.

You might also like