无法获取Oracle TO DATE上的记录 [英] Unable to fetch the records on TO DATE Oracle
本文介绍了无法获取Oracle TO DATE上的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据库-表格
PROD.APPLICATION
Game ID Generated Date
1 Jan-01-1995
2 Aug-19-2003
3 Nov-04-2001
4 Sep-26-2007
5 Sep-26-2007
6 Sep-26-2007
7 Sep-19-2007
8 Sep-19-2007
9 Sep-19-2007
10 Jan-11-1985
11 MAY-19-2003
12 Sep-22-2007
13 Sep-22-2007
我运行了以下查询
SELECT *
FROM PROD.APPLICATION JOIN PROD.STATUS ON (PROD.STATUS_ID = REF_STATUS.STATUS_ID)
AND PROD.APPLICATION.GENERETED_DT >= to_date('2007-09-19', 'yyyy-MM-dd') AND
PROD.APPLICATION.GENERETED_DT <= to_date('2007-09-26', 'yyyy-MM-dd');
搜索2007年9月19日至2007年9月26日的记录,即8条记录.
to search for the records from Sep 19 2007 to Sep 26 2007 ie 8 records.
导致仅显示2007年9月19日至2007年9月22日的记录,即仅5条记录
Which has resulted in showing the only records for Sep 19 2007 znd Sep 22 2007 ie only 5 records
Actual Output
Game ID Generated Date
7 Sep-19-2007
8 Sep-19-2007
9 Sep-19-2007
12 Sep-22-2007
13 Sep-22-2007
如何生成搜索查询,以便我可以获取所有8条记录-即这些日期的记录
How to generate the search query so that I could get all the 8 records - ie the records on those dates aswell
预期产量
4 Sep-26-2007
5 Sep-26-2007
6 Sep-26-2007
7 Sep-19-2007
8 Sep-19-2007
9 Sep-19-2007
12 Sep-22-2007
13 Sep-22-2007
尝试
SELECT *
FROM PROD.APPLICATION JOIN PROD.STATUS ON (PROD.STATUS_ID = REF_STATUS.STATUS_ID)
AND PROD.APPLICATION.GENERETED_DT >= to_date('2007-09-19', 'yyyy-MM-dd') AND
PROD.APPLICATION.GENERETED_DT = to_date('2007-09-26', 'yyyy-MM-dd');
没有记录恢复
推荐答案
日期可能具有时间成分.这是Oracle date
数据类型的一部分-但查询时通常不会显示.
The date probably has a time component. This is part of the date
data type in Oracle -- but is often not shown when you query.
更好的方法使用以下逻辑:
A better approach uses the following logic:
SELECT *
FROM PROD.APPLICATION A JOIN
PROD.STATUS S
ON A.STATUS_ID = S.STATUS_ID
WHERE A.GENERATED_DT >= DATE '2007-09-19' AND
A.GENERATED_DT < DATE '2007-09-27';
注意:
-
< DATE '2007-09-27'
将包括前一天的所有日期时间. -
DATE
关键字以YYYY-MM-DD格式引入日期常量. - 表别名使查询更易于编写和阅读.
- 将条件移到
WHERE
子句对查询没有影响,但是对于INNER JOIN
,这种过滤通常在WHERE
子句中完成.
- The
< DATE '2007-09-27'
will include all datetimes from the day before. - The
DATE
keyword introduces a date constants with the format YYYY-MM-DD. - Table aliases make the query easier to write and to read.
- Moving the condition to the
WHERE
clause has no effect on the query, but such filtering is more commonly done in theWHERE
clause for anINNER JOIN
.
这篇关于无法获取Oracle TO DATE上的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文