Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Oracle : decode on date value

SOLVED
Go to solution
Nicolas Dumeige
Esteemed Contributor

Oracle : decode on date value

Hello,

I need to get the last worked day, if current day is monday, then friday.

This doesn't work :

select decode( to_char(to_date('030504','DDMMRR'),'DAY'),
'MONDAY', next_day(sysdate-6,'FRIDAY'),
sysdate-1)

any idea ?

Cheers

Nicolas
All different, all Unix
3 REPLIES
Solution

Re: Oracle : decode on date value

Hi Nicolas:
If you notice the output of
to_char(to_date('030504','DDMMRR'),'DAY')
is not 'MONDAY' but 'MONDAY---'.
Now if you trim the output of this like this
trim(to_char(to_date('030504','DDMMRR'),'DAY')), it will work.

HTH
Dilip
Jean-Luc Oudart
Honored Contributor

Re: Oracle : decode on date value

Something like :
select sysdate -
(DECODE(TRIM(TO_CHAR((SYSDATE - 1),'Day')), 'Sunday', 2,'Saturday', 1,0) + 1)
from dual

this will be yesterday unless yesterday is Sunday or Saturday.

Regards,
Jean-Luc
fiat lux
Nicolas Dumeige
Esteemed Contributor

Re: Oracle : decode on date value

Thank you guys !
All different, all Unix