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

Check if a number in PL/SQL is a palindrome

王林
Release: 2023-08-31 20:09:18
forward
1559 people have browsed it

检查 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;
Copy after login

Output

Palindrome
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template