oracle仅插入时间

oracle insert only time(oracle仅插入时间)
本文介绍了oracle仅插入时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据作为时间而不是日期插入数据库.如果我使用 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.

这篇关于oracle仅插入时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))