本文介绍了相当于DATEADD(工作日,-3,GETDATE())的Oracle(10g)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找与以下产品等效的Oracle(10g):
I'm looking for the Oracle (10g) equivalent of:
DATEADD(weekday, -3, GETDATE())
来自T-SQL(SQL Server).此从当前日期减去3个工作日.我不在乎假期或类似的事情(而且我可以将自己的时间截断掉).仅排除周末即可.
from T-SQL (SQL Server) . This subtracts 3 weekdays from the current date. I'm not concerned about holidays or anything like that (and I can truncate the time part off myself). Just excluding weekends is fine.
推荐答案
您似乎需要创建一个UDF.
It looks like you need to create a UDF.
CREATE OR REPLACE FUNCTION business_date (start_date DATE,
days2add NUMBER) RETURN DATE IS
Counter NATURAL := 0;
CurDate DATE := start_date;
DayNum POSITIVE;
SkipCntr NATURAL := 0;
Direction INTEGER := 1; -- days after start_date
BusinessDays NUMBER := Days2Add;
BEGIN
IF Days2Add < 0 THEN
Direction := - 1; -- days before start_date
BusinessDays := (-1) * BusinessDays;
END IF;
WHILE Counter < BusinessDays LOOP
CurDate := CurDate + Direction;
DayNum := TO_CHAR( CurDate, 'D');
IF DayNum BETWEEN 2 AND 6 THEN
Counter := Counter + 1;
ELSE
SkipCntr := SkipCntr + 1;
END IF;
END LOOP;
RETURN start_date + (Direction * (Counter + SkipCntr));
END business_date;
由拉里·本顿(Larry Benton)提供,来自此处.
Courtesy of Larry Benton, from here.
这篇关于相当于DATEADD(工作日,-3,GETDATE())的Oracle(10g)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!