I got ” ORA-01858: a non-numeric character was found where a numeric was expected ” error in Oracle database.
ORA-01858: a non-numeric character was found where a numeric was expected
Details of error are as follows.
ORA-01858: a non-numeric character was found where a numeric was expected Cause: The input data to be converted using a date format model was incorrect. The input data did not contain a number where a number was required by the format model. Action: Fix the input data or the date format model to make sure the elements match in number and type. Then retry the operation.
a non-numeric character was found where a numeric was expected
This ORA-01858 errors are related with the The input data to be converted using a date format model was incorrect.
The input data did not contain a number where a number was required by the format model.
To solve this error, you need to Fix the input data or the date format model to make sure the elements match in
number and type. Then retry the operation.
An example of the this error as follows:
The DATA in SCOTT.EMP is as follows:
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ------- ---------- --------- ---------- --------- ----- ------- ---------- 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 8000 HAMBURGLAR THIEF 7698 03-MAR-09 100 30
SQL> alter session set NLS_DATE_FORMAT='MM/DD/YYYY'; Session altered. SQL> alter session set NLS_TIMESTAMP_FORMAT='YYYY-MM-DD-hh24.mi.ss.ff'; Session altered. SQL> select * from scott.emp where job='THIEF' and TO_DATE(TO_CHAR(HIREDATE, 'DD-MON-YY')) = TO_DATE(TO_CHAR(sysdate-1, 'DD-MON-YY')); select * from scott.emp where job='THIEF' and TO_DATE(TO_CHAR(HIREDATE, 'DD-MON-YY')) = TO_DATE(TO_CHAR(sysdate-1, 'DD-MON-YY')) * ERROR at line 1: ORA-01858: a non-numeric character was found where a numeric was expected SQL> select /*+ rule*/* from scott.emp where job='THIEF' and TO_DATE(TO_CHAR(HIREDATE, 'DD-MON-YY')) = TO_DATE(TO_CHAR(sysdate-1, 'DD-MON-YY')); select /*+ rule*/* from scott.emp where job='THIEF' and TO_DATE(TO_CHAR(HIREDATE, 'DD-MON-YY')) = TO_DATE(TO_CHAR(sysdate-1, 'DD-MON-YY')) * ERROR at line 1: ORA-01843: not a valid month
Once the NLS Formats are changed back the query now executes without error:
SQL> alter session set NLS_DATE_FORMAT='DD-MON-RR'; Session altered. SQL> alter session set NLS_TIMESTAMP_FORMAT='DD-MON-RR HH.MI.SSXFF AM'; Session altered. SQL> select * from scott.emp where job='THIEF' and TO_DATE(TO_CHAR(HIREDATE, 'DD-MON-YY')) = TO_DATE(TO_CHAR(sysdate-1, 'DD-MON-YY')); no rows selected SQL> select /*+ rule*/* from scott.emp where job='THIEF' and TO_DATE(TO_CHAR(HIREDATE, 'DD-MON-YY')) = TO_DATE(TO_CHAR(sysdate-1, 'DD-MON-YY')); no rows selected
You need to read the following post to learn more details about TO_DATE function.
Do you want to learn Oracle Database for Beginners, then read the following articles.
Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )