The following PL/SQL program checks whether the given string is a palindrome or not:
SET SERVEROUTPUT ON
DECLARE
-- declare the string to be checked
str VARCHAR2(10) := 'RACECAR';
rev VARCHAR(10);
c VARCHAR2(1);
begin
-- for each character from last to first
FOR i IN REVERSE 1..Length(str) LOOP
-- extract each character from string
c := Substr(str, i, 1);
-- concatenate each character to reverse string
rev := rev || c;
END LOOP;
-- check if both string and its reverse are equal
IF rev = str
THEN
dbms_output.put_line(str || ' is a palindrome.');
ELSE
dbms_output.put_line(str || ' is not a palindrome.');
END IF;
END;
/
-- OUTPUT : RACECAR is a palindrome.
We first declare the variables str (the string to be checked), rev
(to store the reversed string), and c (to extract each character). Using a FOR loop that iterates from the length of the string to 1, we extract each character from the string and concatenate it to the reversed string. Finally, we check if
str and rev are equal. If they are, the string is a palindrome.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The following PL/SQL program checks whether the given string is a palindrome or not:
We first declare the variables str (the string to be checked), rev (to store the reversed string), and c (to extract each character). Using a FOR loop that iterates from the length of the string to 1, we extract each character from the string and concatenate it to the reversed string. Finally, we check if str and rev are equal. If they are, the string is a palindrome.