Thursday, November 17, 2011

Reverse a Number in PL/SQL Programming

It is a sample PL/SQL program to take input a number form user and print reverse of accepted number.

Aim - PL/SQL Program to accept a number from user and print number in reverse order.

Program: -
declare
  num1 number(5);
  num2 number(5); 
  rev number(5);
begin
  num1:=&num1;
  rev:=0;
  while num1>0
  loop
    num2:=num1 mod 10;
    rev:=num2+(rev*10);
    num1:=floor(num1/10);
  end loop;
  dbms_output.put_line('Reverse number is: '||rev);
end;


Output: -
Enter value for num1: 12345
old 8: num1:=&num1;
new 8: num1:=12345;
Reverse number is: 54321



6 comments:

Digbijayee Pradhan said...

Bind variable "0" is not declared

Fakhra Choudhary said...

why u use floor in the block..

Unknown said...

awesome...

Gupta Tree Point said...

Here, floor is used for finding division of number

Unknown said...

Great Explanation and more useful for anyone.Thanks for sharing...
oracle course in chennai

Unknown said...

anyone explain to me the reverce number program by steps
how to the run

Post a Comment

Dont SPAM