Home >Database >Mysql Tutorial >Check if a given year is a leap year in PL/SQL

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

WBOY
WBOYforward
2023-09-22 20:37:02922browse

检查给定年份是否是 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

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;

Output

2012 is leap year

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!

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