如何从Oracle中的日期字段中仅提取日期值? [英] How to extract only date value from date field in Oracle?
问题描述
我是Oracle数据库的新手.我对Oracle中的日期时间概念了解不多. 我面临的问题是要检索在特定日期输入的记录.但是,当我在数据库上执行SQL查询时,它返回零条记录.
I am new to Oracle database.I dont have much knowledge about date-time concepts in Oracle. The problem i am facing is to retrieve records which are entered on a particular date.But when i am executing SQL query on database it returns zero records.
数据库具有日期字段,其中包含具有两个datetime值的记录.
Database has date field which contains records with both datetime value.
SQL查询:SELECT * FROM table WHERE table.daterecord = to_date(03-Mar-2010)
它不返回任何记录,但是如果我将查询更改为
It is not returning any record but if i change my query to
SELECT * FROM table WHERE table.daterecord > to_date(04-Mar-2010)
它将返回一些记录. 以上差异是由于时间原因.我该如何从日期中提取时间值.我可以为此使用trunc函数吗?预先感谢您的宝贵建议.
It will return some records. The above difference is because of time.How can i extract time value from date. Can I use trunc function for this? Thanks in advance for your valuable suggestions.
推荐答案
是的,您可以使用TRUNC函数.
Yes you can use TRUNC function.
SELECT *
FROM table
WHERE TRUNC(table.daterecord) = TO_DATE('03-Mar-2010', 'DD-MON-RRRR')
这篇关于如何从Oracle中的日期字段中仅提取日期值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!