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 中插入日期时月份无效
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
