Oracle 减去天和分钟
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43910819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle subtracting days and minutes
提问by Carlos
I want to subtract "X" days and "X" minutes from sysdate, where the days and minutes are an integer as input parameter. For instance, 10days and 5minutes.
我想从 sysdate 中减去“X”天和“X”分钟,其中天数和分钟是作为输入参数的整数。例如,10天5分钟。
I found many examples to subtract either minutes or hours but not a combination of days and minutes.
我找到了许多减去分钟或小时的例子,但不是天数和分钟数的组合。
select sysdate - 5 / 24 / 60 from dual -- will retrieve sysdate minus 5 minutes.
--What about the days?
Thank you!
谢谢!
回答by MT0
Use an interval literal:
使用区间文字:
SELECT SYSDATE - INTERVAL '10 00:05' DAY(2) TO MINUTE
FROM DUAL
Or:
或者:
SELECT SYSDATE - INTERVAL '10' DAY - INTERVAL '5' MINUTE
FROM DUAL
Or just use arithmetic:
或者只是使用算术:
SELECT SYSDATE - 10 /* Days */ - 5 / 24 /60 /* Minutes */
FROM DUAL
Or use NUMTODSINTERVAL
:
或使用NUMTODSINTERVAL
:
SELECT SYSDATE - NUMTODSINTERVAL( 10, 'DAY' ) - NUMTODSINTERVAL( 5, 'MINUTE' )
FROM DUAL
回答by Gurwinder Singh
You can use Interval day to minute - http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements003.htm#i38598
您可以每天使用间隔 - http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements003.htm#i38598
select sysdate - interval '1 00:05' day to minute from dual