ORA-01858: a non-numeric character was found where a numeric was expected

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.

PL/SQL Datetime Functions

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *