PL/SQL Program for Reversing a Number
Here you will learn pl/sql program for reversing a number. Reversing number means reverse the digits of a number.
For example:
Input Number = 15876
Reverse number = 67851
PL/SQL Program for Reversing a Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | DECLARE num NUMBER; reverse_num NUMBER := 0; remainder NUMBER; BEGIN -- get user input DBMS_OUTPUT.PUT_LINE('Enter a number: '); num := # DBMS_OUTPUT.PUT_LINE('Input number is : ' || num); WHILE num > 0 LOOP remainder := num MOD 10; -- store last digit of number reverse_num := reverse_num * 10 + remainder; -- Add digit to reversed number num := num / 10; -- Remove the last digit from input number END LOOP; DBMS_OUTPUT.PUT_LINE('Reversed number: ' || reverse_num); END; / |
Output
Enter a number: 15876
Input number is : 15876
Reversed number: 67851
Check out our other PL/SQL programs examples