PL/SQL Program for Palindrome String
Here you will learn pl/sql program for palindrome string using substr function in pl/sql programming.
PL/SQL Program for Palindrome String
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 28 29 | DECLARE old_str VARCHAR2(50); new_str VARCHAR2(50); BEGIN -- Prompt to get user input DBMS_OUTPUT.PUT_LINE('Enter a string:'); -- store user input old_str := '&input_string'; -- Loop to reverse the old string FOR i IN REVERSE 1..LENGTH(old_str) LOOP new_str := new_str || SUBSTR(old_str, i, 1); END LOOP; -- Print Old and New Reversed strings DBMS_OUTPUT.PUT_LINE('Old String: ' || old_str); DBMS_OUTPUT.PUT_LINE('New String: ' || new_str); -- Check if the old string is equal to new string IF old_str = new_str THEN DBMS_OUTPUT.PUT_LINE('The string is a palindrome.'); ELSE DBMS_OUTPUT.PUT_LINE('The string is not a palindrome.'); END IF; END; / |
Output 1
Enter a string: gaman
Old String: gaman
New String: namag
The string is not a palindrome.
Output 2
Enter a string: madam
Old String: madam
New String: madam
The string is a palindrome.
Check out our other PL/SQL programs examples