24 Oct 2013

Leap Year

Leap Year Query

select  extract(year from hiredate) years,
       decode( mod(extract(year from hiredate), 4), 0,
          decode( mod(extract(year from hiredate), 400), 0, 'Leap Year',
             decode( mod(extract(year from hiredate), 100), 0, 'Not a Leap Year', 'Leap Year')
          ), 'Not a Leap Year'
       ) as leap_year_indicator
from   emp;

Output Look Like
------------------------
YEARS LEAP_YEAR_INDICATOR
1980 Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1987 Not a Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1987 Not a Leap Year
1981 Not a Leap Year
1981 Not a Leap Year
1982 Not a Leap Year
2003 Not a Leap Year

No comments:

Post a Comment