Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get employees whose birthday falls in next 7 days

Soukaina IDRISSIOct 29 2018 — edited Oct 29 2018

Hi everyone,

I have the 'EMPLOYEES' table, and i want to know who are the employees whose birthday falls in next 7 days.

So for that i created this query:

SELECT   *

  FROM   employees

WHERE   (EXTRACT (MONTH FROM birth_date) * 31

          + EXTRACT (DAY FROM birth_date) >=

              EXTRACT (MONTH FROM SYSDATE) * 31 + EXTRACT (DAY FROM SYSDATE)

          AND EXTRACT (MONTH FROM birth_date) * 31

             + EXTRACT (DAY FROM birth_date) <=

                 EXTRACT (MONTH FROM SYSDATE + 6) * 31

                 + EXTRACT (DAY FROM SYSDATE + 6));

But the problem is:

The query works only if SYSDATE is between'01/01/2018' and '31/12/2018', but when the sysdate = '01/01/2019' the query doesnt work anymore.

Thank you for help.

Comments
Post Details
Added on Oct 29 2018
15 comments
4,402 views