Suppose your input is a date (any date), and you must compute "the previous workday" from that input, where "workweek" is defined as Monday through Friday. There are additional assumptions and requirements: the input date is a workday, and it may have time-of-day different from midnight; the output date must have time-of-day of midnight, and we don't need to consider "holidays" (off days that fall on a workday, such as Independence Day).
You can do something like this:
select trunc(input_date) - case when to_char(input_date, 'Dy') = 'Mon'
then 3 else 1 end
from ...
This assumes your session's date language is English (or American or similar); if it is not, or if it may not be in the future or for another user, you can use the third argument to to_char
:
to_char(input_date, 'Dy', 'nls_date_language=English')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…