PL/SQL Program for Palindrome Number
Here you will learn pl/sql program for palindrome number using substr function in pl/sql programming.
PL/SQL Program for Palindrome Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | DECLARE input_number NUMBER := &Enter_Number; -- User will input the number rev_number NUMBER := 0; -- variable to store reverse number temp NUMBER; -- variable to store temp number rem NUMBER; -- variable to store remainder number BEGIN temp := input_number; -- reverse the digits of number WHILE temp > 0 LOOP remainder := MOD(temp, 10); -- Get the last digit rev_number := (rev_number * 10) + rem; -- Build the reversed number temp_number := FLOOR(temp_number / 10); -- Remove the last digit from the number END LOOP; -- Print input and reversed numbers DBMS_OUTPUT.PUT_LINE('Input Number: ' || input_number); DBMS_OUTPUT.PUT_LINE('Reversed Number: ' || rev_number); -- Check if input number is equal to the reversed number IF input_number = rev_number THEN DBMS_OUTPUT.PUT_LINE('The number is a palindrome.'); ELSE DBMS_OUTPUT.PUT_LINE('The number is not a palindrome.'); END IF; END; / |
Output
Enter_Number 1259
Input Number: 1259
Reversed Number:9521
The number is not a palindrome.
Output
Enter_Number 12321
Input Number: 12321
Reversed Number: 12321
The number is a palindrome.
Check out our other PL/SQL programs examples