關於時間跨度比較的OVERLAPS函式
我曾經在我的部落格http://hitc.blogdriver.com/hitc/1288452.html 裡介紹瞭如何使用工作區管理器(workspace)來管理時態。但必須首先配置好工作區管理器。 由於blogdriver 空間有問題,所以計劃把部落格遷到ITPUB。
今天檢視抓蝦訂閱的部落格,看到這麼Kevin Meade 的Undocumented OVERLAPS Function, Don't Use it Yet ,文中提到OVERLAPS函式,例如:
SQL> SELECT *
2 FROM dual
3 WHERE (add_months(sysdate, -6), DATE '2008-08-08')
4 OVERLAPS
5 (sysdate - 180, interval '2' YEAR);
D
-
X
在Mimer SQL Reference Manual: 中對OVERLAPS進行了一些解釋:
The OVERLAPS predicate tests whether two “events” cover a common point in time or not, and has the form.:
(expression, expression) OVERLAPS (expression, expression)
Each of the two “events” specified on either side of the OVERLAPS keyword is a period of time between two specified points on the timeline. The two points can be specified as a pair of datetime values or as one datetime value and an INTERVAL offset.
Each “event” is defined by a two expressions constituting a row value expression having two columns.
The first column in each row value expression must be a DATE, TIME or TIMESTAMP and the value in the first column of the first “event” must be comparable.
The second column in each row value expression may be either a DATE, TIME or TIMESTAMP that is comparable with the value in the first column or an INTERVAL with a precision that allows it to be added to the value in the first column.
The value in the first column of each row value expression defines one of the points on the timeline for the event.
If the value in the second column of the row value expression is a datetime, it defines the other point on the timeline for the event.
If the value in the second column of the row value expression is an INTERVAL, the other point on the timeline for the event is defined by adding the values in the two column of the row value to expression together.
The NULL value is assumed to be a point that is infinitely late in time.
Either of the two points may be the earlier point in time.
If the value in the first column of the row value expression is the NULL value, then this is assumed to be the later point in time.
從這裡,我們可以看出OVERLAPS有兩種用法:
除了本文開始提到的例子外,還有:
SQL> select * from dual
2 where (date '2007-01-01', interval '5' year)
3 overlaps (date '2005-01-01', interval '10' year);
D
-
X
比較的只能是日期,而不是數字,例如:
SQL> select * from dual
2 where (1,5)
3 overlaps (3,8) ;
where (1,5)
*
ERROR at line 2:
ORA-00932: inconsistent datatypes
由於這個函式是ORACLE的未公開的,所以不宜在產品系統中使用。一個Kevin Meade給出的替代方法:
where (s2 < e1 and e2 > s1) or (s1 < e2 and e1 > s2)
這個函式最早出現在David Aldridge’s的
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9036/viewspace-446865/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySql 時間比較:DATEDIFF函式與大於小於號MySql函式
- C語言中關於時間的函式函式
- 時間函式對比函式
- 【C/C++】計時函式比較C++函式
- 使用jiffies的時間比較函式time_after、time_before函式
- MySQL 5.7關於日期和時間的函式整理MySql函式
- jquery比較時間 的時分秒大小jQuery
- JavaScript 比較時間大小JavaScript
- 幾個分析函式的比較函式
- Python的內建比較函式cmp比較原理剖析Python函式
- postgresql 比較兩個時間差大於 N個小時SQL
- Oracle 中 replace函式和translate函式比較Oracle函式
- 【SQL】使用分析函式與關聯子查詢的比較SQL函式
- JavaScript比較兩個時間JavaScript
- JavaScript比較時間日期大小JavaScript
- Mysql 一個比較好用的函式MySql函式
- java計算時間差及比較時間Java
- 關於 Date 函式獲取各類時間/日期/天數函式
- 常用函式--時間函式函式
- 關於Android room 時間函式條件的坑 給需要的人AndroidOOM函式
- 時間函式函式
- MySQL:MySQL層比較函式呼叫MySql函式
- java計算時間差及比較時間大小Java
- JavaScript比較兩個時間大小JavaScript
- C sharp 比較時間大小C Sharp
- JavaScript - 函式 setTimeout 和 setInterval 的比較JavaScript函式
- C語言的比較庫函式--qsortC語言函式
- 拷貝建構函式(比較全的)函式
- javascript比較兩個時間日期的大小JavaScript
- python中關於時間和日期函式的常用計算總結Python函式
- 關於Oracle字元型別的比較Oracle字元型別
- JavaScript 匿名函式與具名函式執行效率比較JavaScript函式
- js命名函式與匿名函式執行速度比較JS函式
- js匿名函式和具名函式執行效率比較JS函式
- 直播軟體搭建,當前時間、既定時間後的時間及時間比較大小
- 直播平臺開發,純時間比較(時分),不含日期,js前端比較JS前端
- 關於Go tools的比較有用的flagsGo
- PHP 時間函式PHP函式