PL/SQL Program to Check String is Palindrome or Not

PL/SQL Program to Check String is Palindrome or Not:



declare
str varchar(15);
rev varchar(15);
slen number(10);
c char(1);
Begin
str:=:str;
slen:=length(str);
for i in reverse 1..slen
loop
c:=substr(str,i,1);
rev:=rev||c;
end loop;
dbms_output.put_line('Original String: '||str);
dbms_output.put_line('Reversed String: '||rev);
if(str = rev) then
dbms_output.put_line('Given string is Palindrome');
else
dbms_output.put_line('Given string is not Palindrome');
end if;
end;

OUTPUT:

Original String: NITIN
Reversed String: NITIN
Given string is Palindrome
--------------------------------------------
Original String: PROGRAM
Reversed String: MARGORP
Given string is not Palindrome

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen − 4 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.