2013-07-18 62 views
0

间数日我有一些数据类型代表日期 场如:20060421甲骨文比较两个日期

我在其他表中的其他两个字段与日期的数据类型。

我想检索位于另一个表中存在的那两个日期之间的第一个表中的行。

如何比较数据类型Date的两个日期的between子句中简单数字格式的日期。

回答

1

我认为这里最简单的解决方案是将数字日期转换为日期类型,然后使用内置的BETWEEN函数。

-- sample cast 
select to_date(to_char(20060801),'YYYYMMDD') from dual 

所以您的解决方案应该是这个样子:

select * 
from numericDatesTable t1, otherTable t2 
where to_date(to_char(t1.date),'YYYYMMDD') between t2.date1 and t2.date2