甲骨文只插入时间 [英] oracle insert only time
问题描述
我想将数据作为时间而不是日期插入数据库.如果我使用to_date('2012-08-31 07:39:33', 'YYYY-MM-DD HH24:MI:SS')
,它也会添加日期.
如果我使用to_date('09:34:00', 'HH24:MI:SS')
,那么它也会从无处添加年,月,日:|
稍后,我需要获取时间介于x和y之间的行,而不考虑年,月或日.我怎么做?
谢谢
I would like to insert data to db as time, not date. If I use to_date('2012-08-31 07:39:33', 'YYYY-MM-DD HH24:MI:SS')
it adds date too.
If I use to_date('09:34:00', 'HH24:MI:SS')
it adds year, month, day as well, from nowhere :|
Later I need to get rows where time is between x and y, not taking in account the year, month or day. How do I do that?
thanks
推荐答案
DATE
类型始终包含日期部分.
A DATE
type always includes the date component.
一种选择是继续使用DATE
并编写代码以忽略日期部分.为了使查询更加高效,您可能需要在TO_CHAR( date_field, 'HH24:MI:SS' )
之类的对象上创建基于函数的索引,并在查询中使用该表达式.
One option is to continue using DATE
and write your code to ignore the date component. In order to make queries on the time efficient, you might want to create a function-based index on something like TO_CHAR( date_field, 'HH24:MI:SS' )
and use that expression in your queries.
或者,您可以使用NUMBER
字段存储自午夜以来的秒数,并以此来编写查询.
Alternatively, you could use a NUMBER
field to store the number of seconds since midnight, and write your queries in terms of that.
这篇关于甲骨文只插入时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!