首頁  >  文章  >  資料庫  >  檢查給定年份是否為 PL/SQL 中的閏年

檢查給定年份是否為 PL/SQL 中的閏年

WBOY
WBOY轉載
2023-09-22 20:37:02876瀏覽

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

這裡我們將看到如何使用 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

以上是檢查給定年份是否為 PL/SQL 中的閏年的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除