当前位置: 首页 > 新闻动态 > 技术教程

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

作者:WBOY 浏览: 发布日期:2023-09-22
[导读]:这里我们将看到如何使用PL/SQL检查给定年份是否是闰年。在PL/SQL代码中,一些命令组被排列在相关的语句声明块中。闰年检查算法如下。算法isLeapYear(year):begin  ifyearisdivisibleby4andnotdivisibleby100,then   itisleapyear  elseifthenumberisdivisibleby400

这里我们将看到如何使用 PL/SQL 检查给定年份是否是闰年。在PL/SQL代码中,一些命令组被排列在相关的语句声明块中。

闰年检查算法如下。

算法

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

示例

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;

输出

2012 is leap year
免责声明:转载请注明出处:http://sczxchw.cn/news/509499.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!