I have to select
some data from Oracle 11g
database, but I can't seem to figure out why following select
query is failing:
SELECT
INFO_ID,
INFO_DETAIL,
IMPORTANT_FLG,
DELETE_FLG,
CREATE_TIME,
DISPLAY_ORDER
FROM TABLE_NAME
WHERE TO_DATE(TO_CHAR(CREATE_TIME, 'YYYY/MM/DD'), 'YYYY/MM/DD')
BETWEEN TO_DATE(TO_CHAR(:fromDate, 'YYYY/MM/DD'), 'YYYY/MM/DD') AND TO_DATE(TO_CHAR(:toDate, 'YYYY/MM/DD'), 'YYYY/MM/DD')
ORDER BY IMPORTANT_FLG DESC NULLS LAST , DISPLAY_ORDER ASC NULLS LAST, CREATE_TIME DESC, INFO_ID ASC
The query is failing with following error message:
ORA-01481: invalid number format model
01481. 00000 - "invalid number format model"
*Cause: The user is attempting to either convert a number to a string
via TO_CHAR or a string to a number via TO_NUMBER and has
supplied an invalid number format model parameter.
My input for the variables fromDate
and toDate
are just date strings such as 20111010
etc. I have tried also more specific time (same format as in the table), but that doesn't seem to be the problem..
In the database the CREATE_TIME
column is TIMESTAMP(6)
type, and for example one sample is 2011/12/19 08:04:42
Any ideas why this is error pops up?
yyyy-MM-dd
) as a format. Have you tried using dashes instead of slashes? – CastorenaTO_CHAR(:fromDate, 'YYYY/MM/DD')
is wrong. You are converting a NUMBER to STRING, assuming it to be DATE.20111010
is not a DATE, it is a NUMBER. Also,'20111010'
is not a DATE, it is a STRING. They are completely different. – Brahmanism