[英]ORA-01843: not a valid month when insert a date in oracle
I'm trying to insert a row in oracle database and when i try with the date i have the errore in title. 我正在尝试在oracle数据库中插入一行,当我尝试使用日期时,我在标题中有错误。 My date is
DD/MM/YYYY HH:MM:SS
(example 25/01/2013 12:07:19
) 我的日期是
DD/MM/YYYY HH:MM:SS
(例如25/01/2013 12:07:19
)
edit for better explain: i have an android application and want to insert a row in oracle database by php. 编辑以便更好地解释:我有一个Android应用程序,并希望通过PHP在oracle数据库中插入一行。
in Php i have: 在Php我有:
$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);
where $array['data']
is 25/01/2013 12:07:19
其中
$array['data']
是25/01/2013 12:07:19
ps i know that there are security problems there but it is not a problem for now. ps我知道那里有安全问题,但现在不是问题。
MM
is for month. MM
是一个月。 Use MI
for minutes. 使用
MI
几分钟。
You have 你有
HH:MM:SS
every time where the minutes are greater than 12 will trigger the error as you are telling Oracle to interpret them as months. 每次分钟大于12时都会触发错误,因为您要告诉Oracle将它们解释为几个月。
You are also using HH without am/pm (in your example you just used 12
). 你也在没有am / pm的情况下使用HH(在你的例子中你刚刚使用了
12
)。 If you are using a 24 format use HH24
如果您使用的是24格式,请使用
HH24
DD/MM/YYYY HH24:MI:SS
or if you want the 12-hour format 或者如果你想要12小时格式
DD/MM/YYYY HH:MI:SSAM
and then 接着
02/01/2013 07:42:00am
Edit 编辑
You are inserting the date with the default format which is MM/DD/YYYY (american standard): 25 is not a valid month. 您正在使用默认格式MM / DD / YYYY(美国标准)插入日期:25不是有效月份。 You can use the
TO_DATE
function 您可以使用
TO_DATE
函数
'TO_DATE(' . $array['data'] . ', DD/MM/YYYY HH24:MI:SS)'
使用TO_DATE('20 / 08/2012 09:00:00','DD / MM / YYYY HH24:MI:SS')插入日期以获取更多详细信息,请参阅链接Oracle错误
Just for more info: 仅供参考:
The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved): 定义了以下模式字母(从'A'到'Z'和从'a'到'z'的所有其他字符都是保留的):
Letter Date or Time Component Presentation Examples 信函日期或时间组件演示示例
G Era designator Text AD
y Year Year 1996; 96
Y Week year Year 2009; 09
M Month in year (context sensitive) Month July; Jul; 07
L Month in year (standalone form) Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day name in week Text Tuesday; Tue
u Day number of week (1 = Monday, ..., 7 = Sunday) Number 1
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
X Time zone ISO 8601 time zone -08; -0800; -08:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.