Home  >  Article  >  Database  >  Check if a number in PL/SQL is a palindrome

Check if a number in PL/SQL is a palindrome

王林
王林forward
2023-08-31 20:09:181524browse

检查 PL/SQL 中的数字是否为回文

In this section, we will see how to check if a number is a palindrome using PL/SQL. In PL/SQL code, certain groups of commands are arranged within blocks of related statement declarations.

A number is a palindrome if it is the same as its opposite. Consider the number 12321, which is a 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

The above is the detailed content of Check if a number in PL/SQL is a palindrome. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete