Oracle在查询中仅从To_Date()获得时间? [英] Oracle Get only time from To_Date() in a Query?

查看:344
本文介绍了Oracle在查询中仅从To_Date()获得时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插入查询:

INSERT INTO THE_TABLE (Field_A) 
VALUES (TO_DATE('08/12/2011 08:35:42 AM','HH:MI:SS PM'))
WHERE Something = 'SomethingElse'

Field_A是日期"字段.当我执行查询时,Field_A仍显示日期和时间.

Field_A is a Date field. When I execute the query, Field_A still shows a date and time.

有没有办法只抓住时间?

Is there a way to grab only the time?

我尝试了To_Char(),但是随后它转换为字符串,并且该字段将不接受它.

I have tried To_Char(), but then it converts to a string and the field wont take it.

我也尝试过TO_DATE('08:35:42 AM','HH:MI:SS PM'),但这也不起作用,它仍然在表格中显示日期和时间.

I have also tried TO_DATE('08:35:42 AM','HH:MI:SS PM') and that doesn't work either, it still shows a date and time in the table.

推荐答案

如果您的字段是日期字段,则将始终具有日期时间中的日期部分.

If your field is a date field, you will always have the date portion of your date time.

您可以将其存储为其他内容,例如秒数,并使用转换功能将其转换为时间.既然TO_CHAR似乎不需要一个数字并将其转换一次,所以您必须在应用程序端执行此操作.

You could store it as something else, like just the number of seconds and use a conversion function to convert it to a time. Since it seems like TO_CHAR won't take a number and convert it a time, you'd have to do this on the application side.

所以我还是将其存储为DATE以避免混淆;使用时只需忽略日期部分即可.

So I'd just store it as a DATE anyways to avoid confusion; just ignore the date portion when using it.

顺便说一句,

我尝试了To_Char(),但是随后它转换为字符串,并且该字段将不接受它.

I have tried To_Char(), but then it converts to a string and the field wont take it.

不太正确,因为正确格式的字符串会隐式转换为DATE s.

Is not quite right, because strings in the correct format are implicitly converted to DATEs.

这篇关于Oracle在查询中仅从To_Date()获得时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆