Home > Database > Mysql Tutorial > body text

Check if a given year is a leap year in PL/SQL

WBOY
Release: 2023-09-22 20:37:02
forward
858 people have browsed it

检查给定年份是否是 PL/SQL 中的闰年

Here we will see how to check if a given year is a leap year using PL/SQL. In PL/SQL code, groups of commands are arranged in blocks of related statement declarations.

The leap year check algorithm is as follows.

Algorithm

isLeapYear(year):
begin
   if year is divisible by 4 and not divisible by 100, then
      it is leap year
   else if the number is divisible by 400, then
      it is leap year
   else
      it is not leap year
end
Copy after login

Example

DECLARE
   year NUMBER := 2012;
BEGIN
   IF MOD(year, 4)=0
      AND
      MOD(year, 100)!=0
      OR
      MOD(year, 400)=0 THEN
      dbms_output.Put_line(year || ' is leap year ');
   ELSE
      dbms_output.Put_line(year || ' is not leap year.');
   END IF;
END;
Copy after login

Output

2012 is leap year
Copy after login

The above is the detailed content of Check if a given year is a leap year in PL/SQL. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!