SQL oracle中的区间函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5879448/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:24:04  来源:igfitidea点击:

interval function in oracle

sqloracle

提问by Aaaaa

Query:

询问:

SELECT INTERVAL '300' month,
       INTERVAL '54-2' year to month,
       INTERVAL ' 11:12:10.1234567' hour to second 
  FROM DUAL;

The output of the above query is:

上述查询的输出是:

+25-00,+54-02,+00 11:12:10.1234567

Can someone please explain to me how this query is giving this output, with an explanation about the interval function?

有人可以向我解释这个查询是如何给出这个输出的,并解释一下间隔函数吗?

回答by a_horse_with_no_name

INTERVALis not a function it's a keyword that introduces an interval literaland such denotes a data type. Similar to what the literals DATE '2011-05-04'or TIMESTAMP '2011-05-04 17:18:19'are doing.

INTERVAL不是函数,它是一个关键字,它引入了区间文字,表示数据类型。类似于文字DATE '2011-05-04'TIMESTAMP '2011-05-04 17:18:19'正在做的事情。

Details about interval literals
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements003.htm#SQLRF00221
http://docs.oracle.com/cd/E11882_01/server.112/e41084/expressions009.htm#SQLRF52084

有关区间文字的详细信息
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements003.htm#SQLRF00221
http://docs.oracle.com/cd/E11882_01/server.112/e410894/expressions000 .htm#SQLRF52084

Details about the interval datatype:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#i128552

关于区间数据类型的详细信息:http:
//docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements001.htm#i128552

回答by Rashmi Rathour

Interval is a function which is used to deduct or add (days,years,months,hour,minutes and seconds) to the given date. interval '300' month : 25-0 Reason : 300/12(months) gives you quotient as 25 and remainder as 0 so the output will be 25-0

间隔是一个函数,用于减去或添加(天、年、月、小时、分钟和秒)到给定的日期。间隔 '300' 月:25-0 原因:300/12(months) 为您提供商为 25,余数为 0,因此输出将为 25-0

interval '54-2' year to month : 54-2 Reason : As you have not mentioned any date it is giving as it is. if you use select sysdate + interval '54-2' year to month from dual; output will be : 1-12-2066

间隔'54-2'年到月:54-2 原因:由于您没有提到任何日期,它按原样给出。如果您使用 select sysdate + interval '54-2' year to month from dual; 输出将是:1-12-2066

sydate : 1-10-2012 so adding 54 to 12 = 66 and adding 2 months to oct which will be dec.

sydate : 1-10-2012 所以将 54 添加到 12 = 66 并将 2 个月添加到 oct,即 12 月。

Same with the last option as well.

与最后一个选项相同。