Taking advantage of the fact that February 29th only exists in a leap year:
SQL*Plus: Release 10.2.0.1.0 - Production on Ti Apr 25 22:20:21 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE OR REPLACE
2 FUNCTION leap_year(
3 p_year IN NUMBER)
4 RETURN BOOLEAN
5 IS
6 l_dato DATE;
7 date_not_valid EXCEPTION;
8 PRAGMA EXCEPTION_INIT(date_not_valid,-1839);
9 BEGIN
10 l_dato:=TO_DATE('2902'||LPAD(TO_CHAR(p_year),4,'0'),'DDMMYYYY');
11 RETURN TRUE;
12 EXCEPTION
13 WHEN date_not_valid THEN
14 RETURN FALSE;
15 WHEN OTHERS THEN
16 RETURN NULL;
17 END;
18 /
Function created.
SQL> SET SERVEROUTPUT ON;
SQL> BEGIN
2 FOR y IN 1998..EXTRACT(YEAR FROM SYSDATE) LOOP
3 DBMS_OUTPUT.PUT(TO_CHAR(y)||' is ');
4 IF NOT leap_year(y) THEN
5 DBMS_OUTPUT.PUT('NOT');
6 END IF;
7 DBMS_OUTPUT.PUT_LINE(' a leap year!');
8 END LOOP;
9 END;
10 /
1998 is NOT a leap year!
1999 is NOT a leap year!
2000 is a leap year!
2001 is NOT a leap year!
2002 is NOT a leap year!
2003 is NOT a leap year!
2004 is a leap year!
2005 is NOT a leap year!
2006 is NOT a leap year!
PL/SQL procedure successfully completed.