将TIME插入Oracle SQL,DATE字段 [英] Insert TIME into Oracle SQL, DATE field

查看:115
本文介绍了将TIME插入Oracle SQL,DATE字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试插入:

  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屋!

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