Open In App
Related Articles

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

Improve Article
Save Article
Like Article

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.

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:

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


abccba is palindrome
Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation course.

Last Updated : 12 Jul, 2018
Like Article
Save Article
Similar Reads