Reverse a number using PL/SQL

Reverse a number using PL/SQL, www.askhareesh.com

DECLARE
   NUM1   NUMBER;
   NUM2   NUMBER;
   REV    NUMBER;
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;



*/

No comments:

Post a Comment