Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

oracle

I have a function that takes in a collection of SearchCriteria Objects: columnName or Key, operator (<, <=, like, etc), and value.

The function builds up a Command Object. I made the value a command parameter and now my Unit Tests will not work for Dates. But all of my Unit Tests work against all other datatypes like varchar.

In the debugger, one of my date unit tests that fail end up with the cmd looking like this:

SELECT * FROM (SELECT DocumentId 
               FROM idx1_AuthLetters a 
               INNER JOIN Documents b ON a.DocumentId = b.Id
               WHERE Status in ('L','S','V')  AND  letter_date <= :1 
               ORDER BY DOCUMENTID ) 
WHERE RowNum <= 14 

I did have the parameter named like :letter_date. But I might have :letter_date >= ### && :letter_date <= ### where I am looking between two dates. I cannot have the same parameter name twice so I use an i++ counter as parameter name while I am looping through all of my SearchCriteria Objects. Odd to see a parameter named like this I know but it is working for the most part.

If I take this and put in my Query Window, and look inspect the param value and plug that in:

SELECT * FROM (SELECT DocumentId 
               FROM idx1_AuthLetters a 
               INNER JOIN Documents b ON a.DocumentId = b.Id 
               WHERE Status in ('L','S','V')  AND  
                     letter_date <= TO_DATE('2013-1-21', 'yyyy-mm-dd') 
               ORDER BY DOCUMENTID ) 
WHERE RowNum <= 14 

it works fine. But it will not work from the C# code from my Unit Test. Again this works for all other data types. And it use to work before I parameterized the value in the select statement.

Exact error is:

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

like image 336
Sam Avatar asked Jun 13 '13 16:06

Sam


People also ask

Is a non numeric character?

A nonnumeric literal (sometimes called an alphanumeric literal) is a character string delimited at the beginning and at the end by quotation marks or apostrophes.

How do I resolve ORA 01830?

This error can occur when you try to enter a date value without using the TO_DATE function. In Oracle, the default date format is generally DD-MON-YYYY. If you try to enter a date value that does not comply with this format, you need to use the TO_DATE function.

What is Nls_date_format?

NLS_DATE_FORMAT specifies the default date format to use with the TO_CHAR and TO_DATE functions. The default value of this parameter is determined by NLS_TERRITORY . The value of this parameter can be any valid date format mask, and the value must be surrounded by double quotation marks.

What is DD Mon RR in Oracle?

it means if you enter to_date( '01-jan-40', 'dd-mon-rr' ) Oracle will slide around the date based on the current year. In 1999 and 2001 -- that would be the year 2040. As opposed to yy -- where the century is based on the current date.


1 Answers

The answer is really simple here: In your command, build the following string TO_DATE(:1, 'yyyy-mm-dd') . Then, just make sure that string that goes into :1 has accurate format.

Your command text should be this:

SELECT * FROM (SELECT DocumentId 
           FROM idx1_AuthLetters a 
           INNER JOIN Documents b ON a.DocumentId = b.Id
           WHERE Status in ('L','S','V')  AND  letter_date <= TO_DATE(:1, 'yyyy-mm-dd')  
           ORDER BY DOCUMENTID ) 
WHERE RowNum <= 14
like image 182
T.S. Avatar answered Oct 03 '22 05:10

T.S.