You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法向Oracle表插入日期数据:ORA-01843错误求助

Fixing ORA-01843: not a valid month Error When Inserting into Oracle's TEST.SUPPLIER Table

Hey there, let's get that date insertion error sorted out! The ORA-01843 error pops up because Oracle can't parse the date string you're using—your session's default date format doesn't match the '2019-06-19' format you're passing in. Here are three reliable ways to fix this:

1. Use TO_DATE() to Explicitly Define the Date Format

This is the most robust approach because it works regardless of your session's default settings. Wrap your date string in the TO_DATE() function and specify the format mask so Oracle knows exactly how to interpret each part:

INSERT INTO TEST.SUPPLIER (SUPPLIER_ID, SUPPLIER_NAME, CONTACT_NAME, DOB)
VALUES(6, 'rr', 'ss', TO_DATE('2019-06-19', 'YYYY-MM-DD'));

The 'YYYY-MM-DD' mask tells Oracle to read the string as year-month-day, eliminating any confusion.

2. Use an ANSI Date Literal

Oracle supports ANSI standard date literals, which use a fixed YYYY-MM-DD format. This is a clean, concise alternative that doesn't require a format mask:

INSERT INTO TEST.SUPPLIER (SUPPLIER_ID, SUPPLIER_NAME, CONTACT_NAME, DOB)
VALUES(6, 'rr', 'ss', DATE '2019-06-19');

Oracle recognizes this syntax automatically, so you don't have to worry about session settings.

3. Adjust Your Session's Date Format (Temporary Fix)

If you prefer using plain string dates, you can temporarily update your session's default date format to match your input. First, check your current format:

SELECT VALUE FROM NLS_SESSION_PARAMETERS WHERE PARAMETER = 'NLS_DATE_FORMAT';

If the result isn't 'YYYY-MM-DD', run this to update it:

ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';

Then execute your original INSERT statement. Note: this change only applies to your current session—once you log out, it will revert to the system default.

Why This Happened

Most Oracle environments use a default date format like 'DD-MON-RR' (e.g., '19-JUN-19'). When you pass '2019-06-19', Oracle tries to interpret -06- as a month abbreviation, which it doesn't recognize—hence the "not a valid month" error.

内容的提问来源于stack exchange,提问作者Sravya Varshini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:44:33