将TIME插入Oracle SQL,DATE字段 [英] Insert TIME into Oracle SQL, DATE field
问题描述
我尝试插入:
13:00
01:00
和
13:00 pm
和
01:00 pm
但是继续收到错误:
不是有效月份
问题是文字。对于日期/时间值,Oracle期望值为ddMMMyyyy。 (或者,您可以使用表达式 DATE'2001-01-01
。文字值解释为这里。)似乎没有一个默认格式的时间没有日期。
换句话说,您可以使用 cast('1/1/2001'as date)
获得相同的错误。
而是使用 to_date()
函数:
选择to_date('10:00','hh:mi')
从双
这样,您可以更加灵活地使用格式。
同样,由于Ben在注释中注明,这给您指定了当前日期。
Is there anyway to insert only time (no date) into a SQL field of type 'Date'
I have tried inserting:
13:00
and
01:00
and
13:00pm
and
01:00pm
But keep getting the error:
Not A Valid Month
The problem is the literal. For date/time values, Oracle expects values in the form ddMMMyyyy. (Or, you can use the expression DATE '2001-01-01
. Literal values are explained here.) There doesn't appear to be a default format for time without a date.
In other words, you can get the same error with cast('1/1/2001' as date)
.
Instead, use the to_date()
function:
select to_date('10:00', 'hh:mi')
from dual
This gives you much more flexibility with formats.
Also, as Ben notes in the comments, this gives you the current date with the time specified.
这篇关于将TIME插入Oracle SQL,DATE字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!