I have to get a date that is 6 months from the system date in Oracle.
And I have to get it by running an open-query from SQL. DATEADD(MONTH,-6, GETDATE())
function serves the purpose in SQL.
Does the function DATEADD(MONTH,-6, GETDATE())
in SQL have an equivalent
function in Oracle?
我必须得到一个日期,从Oracle中的系统日期起6个月。我必须通过运行SQL的开放查询来获得它。DATEADD(MONTH,-6, GETDATE())函数用于SQL。SQL中的DATEADD(MONTH,-6, GETDATE())函数在Oracle中是否具有相同的功能?
3 个解决方案
#1
24
Method1: ADD_MONTHS
Method1:ADD_MONTHS
ADD_MONTHS(SYSDATE, -6)
ADD_MONTHS(SYSDATE,6)
Method 2: Interval
方法2:间隔
SYSDATE - interval '6' month
SYSDATE - interval '6'月。
Note: if you want to do the operations from start of the current month always, TRUNC(SYSDATE,'MONTH')
would give that. And it expects a Date
datatype as input.
注意:如果您希望从当前月开始执行操作,TRUNC(SYSDATE,' month ')会给出这个结果。它需要一个日期数据类型作为输入。
#2
4
Equivalent will be
相当于将
ADD_MONTHS( SYSDATE, -6 )
#3
1
Not my answer :
不是我的回答:
I wasn't too happy with the answers above and some additional searching yielded this :
我对上面的答案不太满意,一些额外的搜索结果是:
SELECT SYSDATE AS current_date,
SYSDATE + 1 AS plus_1_day,
SYSDATE + 1/24 AS plus_1_hours,
SYSDATE + 1/24/60 AS plus_1_minutes,
SYSDATE + 1/24/60/60 AS plus_1_seconds
FROM dual;
which I found very helpful. From http://sqlbisam.blogspot.com/2014/01/add-date-interval-to-date-or-dateadd.html
我觉得很有帮助。从http://sqlbisam.blogspot.com/2014/01/add-date-interval-to-date-or-dateadd.html
#1
24
Method1: ADD_MONTHS
Method1:ADD_MONTHS
ADD_MONTHS(SYSDATE, -6)
ADD_MONTHS(SYSDATE,6)
Method 2: Interval
方法2:间隔
SYSDATE - interval '6' month
SYSDATE - interval '6'月。
Note: if you want to do the operations from start of the current month always, TRUNC(SYSDATE,'MONTH')
would give that. And it expects a Date
datatype as input.
注意:如果您希望从当前月开始执行操作,TRUNC(SYSDATE,' month ')会给出这个结果。它需要一个日期数据类型作为输入。
#2
4
Equivalent will be
相当于将
ADD_MONTHS( SYSDATE, -6 )
#3
1
Not my answer :
不是我的回答:
I wasn't too happy with the answers above and some additional searching yielded this :
我对上面的答案不太满意,一些额外的搜索结果是:
SELECT SYSDATE AS current_date,
SYSDATE + 1 AS plus_1_day,
SYSDATE + 1/24 AS plus_1_hours,
SYSDATE + 1/24/60 AS plus_1_minutes,
SYSDATE + 1/24/60/60 AS plus_1_seconds
FROM dual;
which I found very helpful. From http://sqlbisam.blogspot.com/2014/01/add-date-interval-to-date-or-dateadd.html
我觉得很有帮助。从http://sqlbisam.blogspot.com/2014/01/add-date-interval-to-date-or-dateadd.html