0

我有一个 Oracle DB,我有一个显示日期范围的表:

23/12/2011  08/01/2012
06/01/2012  06/01/2012
19/03/2012  19/03/2012
05/04/2012  05/04/2012
06/04/2012  06/04/2012
30/04/2012  30/04/2012
01/05/2012  01/05/2012
02/05/2012  02/05/2012
15/08/2012  15/08/2012
12/10/2012  12/10/2012
01/11/2012  01/11/2012
06/12/2012  06/12/2012
07/12/2012  07/12/2012
08/12/2012  08/12/2012
25/12/2012  25/12/2012
09/01/2013  26/01/2013
20/05/2013  08/06/2013
24/06/2013  13/07/2013
18/01/2013  02/02/2013
24/05/2013  08/06/2013

我想用一个日期来交叉这个表,检查日期是否不在表的一对日期中,如下所示:

 select * 
from table
where table.date NOT BETWEEN 
(SELECT DT_START FROM CALENDARIO) AND (SELECT DT_END FROM CALENDARIO))

但是 BETWEEN 不接受数组作为条目,那么有什么方法可以实现吗?

提前致谢!

4

3 回答 3

0

我同意@David Aldrige,不存在或不存在。

如果您担心的是性能,则 NOT IN 和交叉连接似乎有更好的解释计划http://sqlfiddle.com/#!4/7159f/6

于 2013-10-18T00:26:19.003 回答
0

你可以试试:

select * 
from table t1
where not exists (
  select null
  from   CALENDARIO
  where  t1.my_date between dt_start and dt_end)
于 2013-10-15T10:47:06.240 回答
0

试试这个希望这对你有帮助

WHERE (d.date1 NOT BETWEEN '2011-11-09 13:08:46' AND '2011-11-11 16:08:46') 
   OR (d.date2 NOT BETWEEN '2011-11-09 13:08:46' AND '2011-11-11 16:08:46') 
   OR (d.date3 NOT BETWEEN '2011-11-09 13:08:46' AND '2011-11-11 16:08:46')
于 2013-10-15T10:07:46.507 回答