Check whether a string is palindrome or not in PL/SQL

Prerequisite PL/SQL introduction
In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations.

Given a string and the task is to find whether it is Palindrome or not.
Examples:

Input: str = geeksskeeg
Output: geeksskeeg is palindrome

Input: str = geeks
Output: geeks is not palindrome

Approach is to take the string, reverse it and check whether the reversed string is equal to the original string or not. If it is equal, then it will be palindrome otherwise not.

Below is the required implementation:

filter_none

edit
close

play_arrow

link
brightness_4
code

DECLARE 
  
    -- Declared variables are s, l, t . 
    -- These variables are of same data type VARCHAR. 
    s VARCHAR2(10) := 'abccba'
    l VARCHAR2(20); 
    t VARCHAR2(10); 
BEGIN 
    FOR i IN REVERSE 1..Length(s) LOOP 
        l := Substr(s, i, 1); 
  
        -- here || are used for concatenation of string. 
        t := t 
             ||'' 
             ||l; 
    END LOOP; 
  
    IF t = s THEN 
      dbms_output.Put_line(t 
                           ||'' 
                           ||' is palindrome'); 
    ELSE 
      dbms_output.Put_line(t 
                           ||'' 
                           ||' is not palindrome'); 
    END IF; 
END
  
-- Program End 

chevron_right


Output:

abccba is palindrome


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.