Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-12-01 · container image gvenzl/oracle-free:23-slim
ORA-01858 comes from converting text to a date. Oracle reads the string and the format model from left to right; when the format says a number comes next (DD, HH24, YYYY) but the text has a letter, it stops with this error.
In 23ai the message reads A non-numeric character was found instead of a numeric character. Compare the text and the format side by side, position by position.
01The format order does not match the text
The column holds Jan 15 2024 (month first) but the format is 'DD MON YYYY' (day first). DD expected digits and found Ja.
Write the format in the same order as the data: 'MON DD YYYY'. Both rows converted: 2024-01-15 and 2024-02-03.
Setup
CREATE TABLE import_orders (order_id NUMBER PRIMARY KEY, order_dt_txt VARCHAR2(20));
INSERT INTO import_orders VALUES (1, 'Jan 15 2024');
INSERT INTO import_orders VALUES (2, 'Feb 03 2024');
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SELECT order_id, TO_DATE(order_dt_txt, 'DD MON YYYY') AS order_date FROM import_orders ORDER BY order_id;SELECT order_id, TO_DATE(order_dt_txt, 'DD MON YYYY') AS order_date FROM import_orders ORDER BY order_id
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT order_id, order_dt_txt FROM import_orders ORDER BY order_id; ORDER_ID ORDER_DT_TXT
---------- --------------------
1 Jan 15 2024
2 Feb 03 2024
2 rows selected.The raw values are Jan 15 2024 and Feb 03 2024: the month name comes first, but the mask starts with DD.
Look at a few raw values first (SELECT col FROM ...). Imported files often use a different order from the one you expect.
SELECT order_id, TO_CHAR(TO_DATE(order_dt_txt, 'MON DD YYYY'), 'YYYY-MM-DD') AS order_date FROM import_orders ORDER BY order_id; ORDER_ID ORDER_DATE
---------- ----------
1 2024-01-15
2 2024-02-03
2 rows selected.02A string compared to a DATE column is converted with NLS_DATE_FORMAT
order_date >= 'Jan 15, 2024' has no TO_DATE, so Oracle converts the string with the session's NLS_DATE_FORMAT, here DD-MON-RR. The first element DD met J and failed. The same SQL can work on another PC with a different setting.
Use a date literal, which does not depend on the session: DATE '2024-01-15'. Order 2 (01-20) was returned.
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, order_date DATE);
INSERT INTO orders VALUES (1, DATE '2024-01-10');
INSERT INTO orders VALUES (2, DATE '2024-01-20');
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-RR';
SELECT order_id FROM orders WHERE order_date >= 'Jan 15, 2024';Session altered.
SELECT order_id FROM orders WHERE order_date >= 'Jan 15, 2024'
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT value FROM nls_session_parameters WHERE parameter = 'NLS_DATE_FORMAT';VALUE
----------------------------------------------------------------
DD-MON-RR
1 row selected.NLS_DATE_FORMAT is DD-MON-RR, so the string 'Jan 15, 2024' is read starting with DD (digits) and fails on J.
Check your session setting with SELECT value FROM nls_session_parameters WHERE parameter = 'NLS_DATE_FORMAT'. Better: never compare a DATE with a plain string.
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-RR';
SELECT order_id FROM orders WHERE order_date >= DATE '2024-01-15';Session altered.
ORDER_ID
----------
2
1 row selected.03Text with AM/PM is read with HH24
The log text is 2024-01-15 PM 3:00, but the format 'YYYY-MM-DD HH24:MI' expects an hour right after the date. HH24 found PM.
Put the meridian in the format and use 12-hour HH: 'YYYY-MM-DD AM HH:MI'. AM in the format matches both AM and PM. Rows came out as 09:05 and 15:00.
Setup
CREATE TABLE app_logs (log_id NUMBER PRIMARY KEY, logged_txt VARCHAR2(30));
INSERT INTO app_logs VALUES (1, '2024-01-15 AM 9:05');
INSERT INTO app_logs VALUES (2, '2024-01-15 PM 3:00');
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SELECT log_id, TO_DATE(logged_txt, 'YYYY-MM-DD HH24:MI') AS logged_at FROM app_logs ORDER BY log_id;SELECT log_id, TO_DATE(logged_txt, 'YYYY-MM-DD HH24:MI') AS logged_at FROM app_logs ORDER BY log_id
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT log_id, logged_txt FROM app_logs ORDER BY log_id; LOG_ID LOGGED_TXT
---------- ------------------------------
1 2024-01-15 AM 9:05
2 2024-01-15 PM 3:00
2 rows selected.Both rows have AM or PM right after the date (2024-01-15 PM 3:00), where HH24 expects the hour digits.
AM/PM words depend on the language. The fix passes 'NLS_DATE_LANGUAGE = AMERICAN' as the third TO_DATE argument so English AM/PM is read the same on any session.
SELECT log_id, TO_CHAR(TO_DATE(logged_txt, 'YYYY-MM-DD AM HH:MI', 'NLS_DATE_LANGUAGE = AMERICAN'), 'YYYY-MM-DD HH24:MI') AS logged_at FROM app_logs ORDER BY log_id; LOG_ID LOGGED_AT
---------- ----------------
1 2024-01-15 09:05
2 2024-01-15 15:00
2 rows selected.04Some rows have separators (2024/01/17) but the format is YYYYMMDD
sales_stage.sale_dt_txt mostly holds 20240115-style text, but one row is 2024/01/17. TO_DATE(sale_dt_txt, 'YYYYMMDD') failed with ORA-01858: after 2024 the format expects the month digits, and the text has / there.
REGEXP_LIKE(sale_dt_txt, '^[0-9]{8}$') found the one row that is not 8 digits: 3 2024/01/17.
Removing the separators first, TO_DATE(REPLACE(REPLACE(sale_dt_txt, '/'), '-'), 'YYYYMMDD'), converted all 3 rows (15-JAN-24, 16-JAN-24, 17-JAN-24).
Setup
CREATE TABLE sales_stage (sale_id NUMBER, sale_dt_txt VARCHAR2(20));
INSERT INTO sales_stage VALUES (1, '20240115');
INSERT INTO sales_stage VALUES (2, '20240116');
INSERT INTO sales_stage VALUES (3, '2024/01/17');
COMMIT;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.SELECT sale_id, TO_DATE(sale_dt_txt, 'YYYYMMDD') AS sale_date FROM sales_stage ORDER BY sale_id;SELECT sale_id, TO_DATE(sale_dt_txt, 'YYYYMMDD') AS sale_date FROM sales_stage ORDER BY sale_id
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT sale_id, sale_dt_txt FROM sales_stage WHERE NOT REGEXP_LIKE(sale_dt_txt, '^[0-9]{8}$'); SALE_ID SALE_DT_TXT
---------- --------------------
3 2024/01/17
1 row selected.Only row 3 (2024/01/17) is not 8 digits; its / sits where YYYYMMDD expects the month.
Data from files and other systems often mixes date styles. Find the odd rows with REGEXP_LIKE before converting, then clean or reject them.
SELECT sale_id, TO_DATE(REPLACE(REPLACE(sale_dt_txt, '/'), '-'), 'YYYYMMDD') AS sale_date FROM sales_stage ORDER BY sale_id; SALE_ID SALE_DATE
---------- ------------------
1 15-JAN-24
2 16-JAN-24
3 17-JAN-24
3 rows selected.05Placeholder text such as N/A in the date column
contract_stage.end_dt_txt holds US-style dates (12/31/2024), but contract 2 has N/A instead of a date. TO_DATE(end_dt_txt, 'MM/DD/YYYY') failed with ORA-01858: MM expects digits and the text starts with N.
VALIDATE_CONVERSION(end_dt_txt AS DATE, 'MM/DD/YYYY') = 0 returns the rows that cannot be converted: 2 N/A.
TO_DATE(end_dt_txt DEFAULT NULL ON CONVERSION ERROR, 'MM/DD/YYYY') runs without changing data: contract 2 comes back empty. To clean the data itself, UPDATE ... SET end_dt_txt = NULL WHERE end_dt_txt = 'N/A'; after that the original TO_DATE converted all 3 rows (2024-12-31, empty, 2025-06-30).
Setup
CREATE TABLE contract_stage (contract_id NUMBER, end_dt_txt VARCHAR2(20));
INSERT INTO contract_stage VALUES (1, '12/31/2024');
INSERT INTO contract_stage VALUES (2, 'N/A');
INSERT INTO contract_stage VALUES (3, '06/30/2025');
COMMIT;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.SELECT contract_id, TO_DATE(end_dt_txt, 'MM/DD/YYYY') AS end_date FROM contract_stage ORDER BY contract_id;SELECT contract_id, TO_DATE(end_dt_txt, 'MM/DD/YYYY') AS end_date FROM contract_stage ORDER BY contract_id
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT contract_id, end_dt_txt FROM contract_stage WHERE VALIDATE_CONVERSION(end_dt_txt AS DATE, 'MM/DD/YYYY') = 0;CONTRACT_ID END_DT_TXT
----------- --------------------
2 N/A
1 row selected.Only the row that cannot be read as MM/DD/YYYY is listed: contract 2 with N/A.
SELECT contract_id, TO_CHAR(TO_DATE(end_dt_txt DEFAULT NULL ON CONVERSION ERROR, 'MM/DD/YYYY'), 'YYYY-MM-DD') AS end_date FROM contract_stage ORDER BY contract_id;CONTRACT_ID END_DATE
----------- ----------
1 2024-12-31
2
3 2025-06-30
3 rows selected.UPDATE contract_stage SET end_dt_txt = NULL WHERE end_dt_txt = 'N/A';
COMMIT;1 row updated.
Commit complete.DEFAULT ... ON CONVERSION ERROR and VALIDATE_CONVERSION were added in 12.2. Converting bad values to NULL hides them, so check the list from VALIDATE_CONVERSION first.
SELECT contract_id, TO_CHAR(TO_DATE(end_dt_txt, 'MM/DD/YYYY'), 'YYYY-MM-DD') AS end_date FROM contract_stage ORDER BY contract_id;CONTRACT_ID END_DATE
----------- ----------
1 2024-12-31
2
3 2025-06-30
3 rows selected.06CSV values still wrapped in double quotes ("15/01/2024")
The staging table was filled from a CSV file and every date kept its double quotes: "15/01/2024". TO_DATE(order_dt_txt, 'DD/MM/YYYY') failed with ORA-01858 because DD expects a digit and the first character is ". The value looks right in a query result, so the quotes are easy to miss.
The check query lists the rows that VALIDATE_CONVERSION(... AS DATE, 'DD/MM/YYYY') cannot convert and dumps their first character: Typ=1 Len=1: 34 for both rows, and 34 is the code of ".
UPDATE order_stage SET order_dt_txt = TRIM(BOTH '"' FROM order_dt_txt) updated 2 rows. The same TO_DATE then returned 2024-01-15 and 2024-02-03.
Setup
CREATE TABLE order_stage (order_id NUMBER, order_dt_txt VARCHAR2(20));
INSERT INTO order_stage VALUES (1, '"15/01/2024"');
INSERT INTO order_stage VALUES (2, '"03/02/2024"');
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SELECT order_id, TO_DATE(order_dt_txt, 'DD/MM/YYYY') AS order_date FROM order_stage ORDER BY order_id;SELECT order_id, TO_DATE(order_dt_txt, 'DD/MM/YYYY') AS order_date FROM order_stage ORDER BY order_id
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT order_id, order_dt_txt, DUMP(SUBSTR(order_dt_txt, 1, 1)) AS first_char FROM order_stage WHERE VALIDATE_CONVERSION(order_dt_txt AS DATE, 'DD/MM/YYYY') = 0 ORDER BY order_id; ORDER_ID ORDER_DT_TXT
---------- --------------------
FIRST_CHAR
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 "15/01/2024"
Typ=1 Len=1: 34
2 "03/02/2024"
Typ=1 Len=1: 34
2 rows selected.Both rows come back, and FIRST_CHAR is Typ=1 Len=1: 34 — character 34 is a double quote, not a digit.
UPDATE order_stage SET order_dt_txt = TRIM(BOTH '"' FROM order_dt_txt);
COMMIT;2 rows updated.
Commit complete.If you load with SQL*Loader or an external table, the usual place to drop the quotes is the loader setting (OPTIONALLY ENCLOSED BY '"'). That setting was not run here; this page only ran the TRIM after loading.
SELECT order_id, TO_CHAR(TO_DATE(order_dt_txt, 'DD/MM/YYYY'), 'YYYY-MM-DD') AS order_date FROM order_stage ORDER BY order_id; ORDER_ID ORDER_DATE
---------- ----------
1 2024-01-15
2 2024-02-03
2 rows selected.07The text starts with a weekday name (Mon, 15 Jan 2024)
Dates copied from mail headers or log lines often start with the weekday: Mon, 15 Jan 2024. TO_DATE(sent_txt, 'DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN') failed with ORA-01858 because DD expects a number and the text starts with Mon,.
The diagnose query lists the rows that VALIDATE_CONVERSION(... AS DATE, 'DD MON YYYY', ...) cannot convert. Both rows came back, and their first five characters are Mon, and Sat,.
Adding DY, to the front of the format reads the weekday as well. With 'DY, DD MON YYYY' all 2 of 2 rows passed VALIDATE_CONVERSION, and TO_DATE returned 2024-01-15 and 2024-02-03.
Setup
CREATE TABLE mail_stage (mail_id NUMBER, sent_txt VARCHAR2(30));
INSERT INTO mail_stage VALUES (1, 'Mon, 15 Jan 2024');
INSERT INTO mail_stage VALUES (2, 'Sat, 03 Feb 2024');
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SELECT mail_id, TO_DATE(sent_txt, 'DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN') AS sent_date FROM mail_stage ORDER BY mail_id;SELECT mail_id, TO_DATE(sent_txt, 'DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN') AS sent_date FROM mail_stage ORDER BY mail_id
*
ERROR at line 1:
ORA-01858: A non-numeric character was found instead of a numeric character.
Help: https://docs.oracle.com/error-help/db/ora-01858/SELECT mail_id, sent_txt, SUBSTR(sent_txt, 1, 5) AS head FROM mail_stage WHERE VALIDATE_CONVERSION(sent_txt AS DATE, 'DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN') = 0 ORDER BY mail_id; MAIL_ID SENT_TXT HEAD
---------- ------------------------------ --------------------
1 Mon, 15 Jan 2024 Mon,
2 Sat, 03 Feb 2024 Sat,
2 rows selected.Both rows appear, and HEAD shows Mon, and Sat,: the text begins with a weekday, not with the day number that DD expects.
SELECT COUNT(*) AS total, SUM(VALIDATE_CONVERSION(sent_txt AS DATE, 'DY, DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN')) AS ok_with_dy FROM mail_stage; TOTAL OK_WITH_DY
---------- ----------
2 2
1 row selected.DY matches the abbreviated weekday in the language given by NLS_DATE_LANGUAGE, so pin it to AMERICAN for English text.
SELECT mail_id, TO_CHAR(TO_DATE(sent_txt, 'DY, DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN'), 'YYYY-MM-DD') AS sent_date FROM mail_stage ORDER BY mail_id; MAIL_ID SENT_DATE
---------- ----------
1 2024-01-15
2 2024-02-03
2 rows selected.FAQ
How do I fix ORA-01858 in TO_DATE?
Make the format match the text exactly, in the same order. Jan 15 2024 needs 'MON DD YYYY', not 'DD MON YYYY'.
Why does the same query work on one PC and fail with ORA-01858 on another?
A string compared to a DATE is converted with the session's NLS_DATE_FORMAT. Use DATE '2024-01-15' or TO_DATE with an explicit format.
How do I convert text with AM/PM to a date?
Use AM and HH (12-hour) in the format, for example 'YYYY-MM-DD AM HH:MI', not HH24.
What is the difference between ORA-01858 and ORA-01861?
ORA-01858 is a letter where a number should be. ORA-01861 is a general mismatch between the literal and the format, such as leftover characters.
How do I find the rows that cause ORA-01858?
Filter the text column with a pattern for the expected format, e.g. WHERE NOT REGEXP_LIKE(col, '^[0-9]{8}$') for YYYYMMDD. In the lab this returned the single 2024/01/17 row.
How do I skip invalid dates in TO_DATE instead of getting ORA-01858?
Use TO_DATE(col DEFAULT NULL ON CONVERSION ERROR, 'MM/DD/YYYY') (12.2+). In the lab the N/A row came back as NULL and the other rows converted.
Why does TO_DATE fail with ORA-01858 on dates imported from a CSV file?
Check whether the values still have the CSV double quotes, like "15/01/2024". DUMP(SUBSTR(col, 1, 1)) showed 34 (a double quote). Remove them with TRIM(BOTH '"' FROM col) before TO_DATE.
How do I convert a date like 'Mon, 15 Jan 2024' with TO_DATE?
Put DY in the format for the weekday: TO_DATE(col, 'DY, DD MON YYYY', 'NLS_DATE_LANGUAGE = AMERICAN'). Without it, DD MON YYYY hits Mon, first and raises ORA-01858.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0