Check if a number is Palindrome in PL/SQLs

PL/SQLMySQLDatabase

In this section we will see how to check whether a number is Palindrome or not using the PL/SQL. In PL/SQL code, some group of commands are arranged within a block of related declaration of statements.

A number is palindrome if the number, and the reverse of that number are same. Suppose a number 12321, this is palindrome, but 12345 is not a palindrome.

Example

DECLARE
   n number;
   m number;
   temp number:=0;
   rem number;
BEGIN
   n :=12321;
   m :=n;
   while n>0
   loop
      rem := mod(n,10);
      temp := (temp*10)+rem;
      n := trunc(n/10);
   end loop;
   if m = temp
   then
      dbms_output.put_line('Palindrome');
   else
      dbms_output.put_line('Not Palindrome');
   end if;
END;

Output

Palindrome
raja
Published on 27-Sep-2019 14:10:41
Advertisements