Showing posts with label reverse a number. Show all posts
Showing posts with label reverse a number. Show all posts

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