This tutorial demonstrates the Oracle PL/SQL interview question of writing a program for finding whether a number or string is a palindrome number or string.

Here I have written an Oracle PL/SQL procedure which takes input an integer or a string which is to be identified for palindrome number or string.

CREATE OR REPLACE PROCEDURE P_CHECK_PALINDROME (P_STR VARCHAR2)
IS
  P_REV_STR VARCHAR2(30);
BEGIN
  FOR I IN REVERSE 1 .. LENGTH(P_STR)
  LOOP
    P_REV_STR := P_REV_STR || SUBSTR(P_STR,I,1);
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('P_REV_STR '||P_REV_STR );
  IF P_STR = P_REV_STR THEN
    DBMS_OUTPUT.PUT_LINE('PALINDROME' );
  ELSE
    DBMS_OUTPUT.PUT_LINE('NOT A PALINDROME' );
  END IF;
END;
/

The procedure can be executed as follows:

SET SERVEROUTPUT ON;
EXEC P_CHECK_PALINDROME ('PLSQL');