I have a query like this:
INSERT INTO some_table (date1, date2)
VALUES (to_date('2012-10-24','YYYY-MM-DD'), to_date('2012-10-24','YYYY-MM-DD'));
but I get:
SQL Error: ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
and:
*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.
but my usage of to_date seems okay?
Many thanks.
That looks correct. And it works for me so there must be something else to the problem that isn’t part of your example…
Are you really using hard-coded literals? Or are the strings you’re passing to
to_datecoming from a table? Is it possible that there is (at least) one row in the table where the data doesn’t match the expected format. Note that a row that is ultimately filtered out by aWHEREclause, even aWHEREclause in a subquery, can still callto_datebefore getting filtered out and cause the error. So it would be perfectly plausible that you would have something likereturn an error.