ORA-01843: not a valid month when insert a date in oracle(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 中插入日期时月份无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ORA-01843: 在 oracle 中插入日期时月份无效
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
