QuestionQ34

VerifiedUsing Single-Row and Aggregate Functions

The EMPLOYEES table has an EMP_ID column of type NUMBER and a HIRE_DATE column of type DATE.

You want to display the date of the first Monday that occurs after six months have passed since each employee's hire date.

The session's NLS_TERRITORY parameter is set to AMERICA, so Sunday is considered the first day of the week.

Which query would you use?

Explanation

The ADD_MONTHS function adds a specified number of months to a date, so ADD_MONTHS(hire_date, 6) gives the date six months after the hire date. The NEXT_DAY function takes a date and a valid day name (as a character string, e.g., 'MONDAY') and returns the date of the first occurrence of that named weekday after the given date. Nesting these as NEXT_DAY(ADD_MONTHS(hire_date, 6), 'MONDAY') correctly returns the first Monday following the six-month mark after hiring. The NLS_TERRITORY setting affecting which day is considered the start of the week does not change the syntax requirement that NEXT_DAY's second parameter be a valid day-name string, so using a numeric value (as in the option using 1) is not the correct or standard usage for this function.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!