ORA-01843: 在 oracle 中插入日期时月份无效 [英] ORA-01843: not a valid month when insert a date in oracle

查看:49
本文介绍了ORA-01843: 在 oracle 中插入日期时月份无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 oracle 数据库中插入一行,当我尝试使用日期时,我的标题中有错误.我的日期是 DD/MM/YYYY HH:MM:SS(例如 25/01/2013 12:07:19)

I'm trying to insert a row in oracle database and when i try with the date i have the errore in title. My date is DD/MM/YYYY HH:MM:SS (example 25/01/2013 12:07:19)

编辑以便更好地解释:我有一个 android 应用程序,想通过 php 在 oracle 数据库中插入一行.
在 PHP 中我有:

edit for better explain: i have an android application and want to insert a row in oracle database by php.
in Php i have:

$sqlString = sprintf("INSERT INTO GUASTI (%s, %s, %s, %s, %s, %s) 
                      VALUES ('%s', '%s', '%s', '%s', '%s', '%s')"
                      ,'guasto','tipo','data', 'localita', 'indirizzo_id', 'utente_id',
                       $array['guasto'], $array['tipo'], $array['data'], $array['localita'], $idUtenti, $idIndirizzo);

其中 $array['data']25/01/2013 12:07:19

附言我知道那里存在安全问题,但现在不是问题.

p.s. i know that there are security problems there but it is not a problem for now.

推荐答案

MM 适用于月份.使用 MI 几分钟.

MM is for month. Use MI for minutes.

你有

HH:MM:SS

每次大于 12 分钟都会触发错误,因为您告诉 Oracle 将它们解释为月份.

every time where the minutes are greater than 12 will trigger the error as you are telling Oracle to interpret them as months.

您还使用不带 am/pm 的 HH(在您的示例中,您只使用了 12).如果您使用 24 位格式,请使用 HH24

You are also using HH without am/pm (in your example you just used 12). If you are using a 24 format use HH24

DD/MM/YYYY HH24:MI:SS

或者如果你想要 12 小时格式

or if you want the 12-hour format

DD/MM/YYYY HH:MI:SSAM

然后

02/01/2013 07:42:00am

编辑

您正在插入默认格式为 MM/DD/YYYY(美国标准)的日期:25 不是有效月份.您可以使用 TO_DATE 函数

You are inserting the date with the default format which is MM/DD/YYYY (american standard): 25 is not a valid month. You can use the TO_DATE function

'TO_DATE(' . $array['data'] . ', DD/MM/YYYY HH24:MI:SS)'

这篇关于ORA-01843: 在 oracle 中插入日期时月份无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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