如何理解oracle的interval時間格式

本篇文章為大家展示了如何理解oracle的interval時間格式,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

創(chuàng)新互聯(lián)技術(shù)團隊10年來致力于為客戶提供成都做網(wǎng)站、網(wǎng)站設(shè)計、品牌網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷推廣、搜索引擎SEO優(yōu)化等服務(wù)。經(jīng)過多年發(fā)展,公司擁有經(jīng)驗豐富的技術(shù)團隊,先后服務(wù)、推廣了上1000+網(wǎng)站,包括各類中小企業(yè)、企事單位、高校等機構(gòu)單位。

INTERVAL:時間間隔

INTERVAL YEAR TO MONTH,年份和月份之間必須有-
包含年、月的一段時間的間隔
INTERVAL 'integer [- integer ]' { YEAR | MONTH } [ (precision) ] [ TO { YEAR | MONTH } ]

'integer [-integer]' specifies integer values for the leading and optional trailing field of the literal. If the leading field is YEAR and the trailing field is MONTH, then the range of integer values for the month field is 0 to 11.
precision is the maximum number of digits in the leading field. The valid range of the leading field precision is 0 to 9 and its default value is 2.
Restriction on the Leading Field :If you specify a trailing field, then it must be less significant than the leading field. For example, INTERVAL '0-1' MONTH TO YEAR is not valid.
"integer [-integer]"指定前導(dǎo)和可選的尾隨字段的整型值。如果前導(dǎo)的字段是年份,而尾隨字段是月,月字段的整數(shù)值范圍為0到11。
"precision"  指定前導(dǎo)字段的最大位數(shù)。前導(dǎo)字段精度的有效范圍為0到9,其默認(rèn)值為2。
前導(dǎo)列的限制:如果您指定了一個尾隨字段,那么它就必須小于前導(dǎo)字段。例如,INTERVAL '0-1'月到Y(jié)EAR是無效的。

select sysdate,sysdate +  interval '1' year from dual;--當(dāng)前時間+1年
select sysdate,sysdate+numtoyminterval(1,'year') as res from dual;--當(dāng)前時間+1年
select sysdate,sysdate +  interval '1-0' year to month from dual;--當(dāng)前時間+1年
select sysdate,sysdate +  interval '1-1' year to month from dual;--當(dāng)前時間+1年1月
select sysdate,sysdate +  interval '100' year(3) from dual;--當(dāng)前時間+100年
select sysdate,sysdate +  interval '100-1' year(3) to month from dual;--當(dāng)前時間+100年1月

select sysdate,sysdate +  interval '100' year(2) from dual;--報錯ORA-01873: 間隔的前導(dǎo)精度太小,因為100是3位數(shù),而2只指定了兩位
select sysdate,sysdate +  interval '100-1' year(2) to month from dual;--報錯ORA-01873: 間隔的前導(dǎo)精度太小,因為100是3位數(shù),而2只指定了兩位


INTERVAL DAY TO SECOND
包含天、小時、分鐘、秒的一段時間的間隔

INTERVAL '{ integer | integer time_expr | time_expr }'
{ { DAY | HOUR | MINUTE } [ (leading_precision) ]
| SECOND [ (leading_precision [, fractional_seconds_precision ]) ]
}
[ TO { DAY | HOUR | MINUTE | SECOND [ (fractional_seconds_precision) ] } ]

'integer' specifies the number of days. If this value contains more digits than the number specified by the leading precision, then Oracle returns an error.
'time_expr' specifies a time in the format HH[:MI[:SS[.n]]] or MI[:SS[.n]] or SS[.n], where n specifies the fractional part of a second. If n contains more digits than the number specified by fractional_seconds_precision, then n is rounded to the number of digits specified by the fractional_seconds_precision value. You can specify time_expr following an integer and a space only if the leading field is DAY.
"integer"指定天數(shù)。如果這個值包含的數(shù)字超過了主要精度指定的數(shù)字,那么Oracle將返回一個錯誤。
"time_expr"指定格式HH:MI:SS的時間。

select sysdate,sysdate+1 from dual;--當(dāng)前時間+1天
select sysdate,sysdate +  interval '1' day from dual;--當(dāng)前時間+1天
select sysdate,sysdate+numtodsinterval(1,'day') as res from dual;--當(dāng)前時間+1天
select sysdate,sysdate +  interval '1 0' day to hour from dual;--當(dāng)前時間+1天
select sysdate,sysdate +  interval '1 1' day to hour from dual;--當(dāng)前時間+1天1小時
select sysdate,sysdate +  interval '1 01:01' day to minute from dual;--當(dāng)前時間+1天1小時1分鐘
select sysdate,sysdate +  interval '1 01:01:01' day to second from dual;--當(dāng)前時間+1天1小時1分鐘1秒
select sysdate,sysdate -interval '1' year,sysdate -interval '1' month,sysdate -interval '1' day,sysdate -interval '1' HOUR,sysdate -interval '1' MINUTE,sysdate-interval '1' second from dual;
--此刻、1年前、1月前、1天前、1小時前、1分鐘、1秒前的時間點

上述內(nèi)容就是如何理解oracle的interval時間格式,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享標(biāo)題:如何理解oracle的interval時間格式
轉(zhuǎn)載注明:http://muchs.cn/article6/ijcoig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站排名、外貿(mào)建站、用戶體驗、自適應(yīng)網(wǎng)站網(wǎng)站設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司