[英]Equivalent function for DATEADD() in Oracle
I have to get a date that is 6 months from the system date in Oracle.我必须得到一个距 Oracle 系统日期 6 个月的日期。
And I have to get it by running an open-query from SQL.我必须通过从 SQL 运行开放查询来获取它。 DATEADD(MONTH,-6, GETDATE())
function serves the purpose in SQL. DATEADD(MONTH,-6, GETDATE())
函数用于 SQL 中的目的。
Does the function DATEADD(MONTH,-6, GETDATE())
in SQL have an equivalent
function in Oracle? SQL 中的DATEADD(MONTH,-6, GETDATE())
函数在 Oracle 中是否具有equivalent
函数?
Method1: ADD_MONTHS方法 1: ADD_MONTHS
ADD_MONTHS(SYSDATE, -6)
SYSDATE - interval '6' month
Note: if you want to do the operations from start of the current month always, TRUNC(SYSDATE,'MONTH')
would give that.注意:如果您想始终从当月开始执行操作, TRUNC(SYSDATE,'MONTH')
会给出。 And it expects a Date
datatype as input.它需要一个Date
数据类型作为输入。
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
等效将是
ADD_MONTHS( SYSDATE, -6 )
--ORACLE SQL EXAMPLE
SELECT
SYSDATE
,TO_DATE(SUBSTR(LAST_DAY(ADD_MONTHS(SYSDATE, -1)),1,10),'YYYY-MM-DD')
FROM DUAL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.