ORA-01843:在oracle中插入日期时无效的月份 [英] ORA-01843: not a valid month when insert a date in 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
)
编辑更好的解释:
i有一个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.
您还使用HH,没有am / pm(在你的例子中,你刚刚使用 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屋!