Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query output based on date - Oracle 8i

New Here ,
Mar 27, 2008 Mar 27, 2008
I am trying to write a very simple query to output data based on date ranges, but I keep encountering an error.

When I do this statement:

select * from my.table
where startdate > '2008-01-01'

I get this error:

[ODBC][Ora]ORA-01861: literal does not match format string


When I format the select statement this way:

select * from my.table
where startdate > #2008-01-01#

i get this error:

[ODBC][Ora]ORA-00932: inconsistent datatypes: expected DATE got NUMBER

Currently using CF8, and what I believe is Oracle 8i. I have tried formatting this data in many other ways, but can't get it to work. I know that when I query the database via access, it has no problem returning results with the SQL date formatted like #01/01/2008#
TOPICS
Database access
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Mar 27, 2008 Mar 27, 2008
You can use the Oracle to_date() function to convert your string to a date/time object:

select * from my.table
where startdate > to_date('2008-01-01', 'YYYY-MM-DD')

Or, since you are using an ODBC connection to Oracle, you can try using the ColdFusion CreateODBCDate() function:

select * from my.table
where startdate > #CreateODBCDate("2008-01-01")#

Or, as already suggested, use cfqueryparam with the appropriate CFSQLType, such as CF_SQL_TIMESTAMP instead of CF_SQL_INTEGER like you are attem...
Translate
Advisor ,
Mar 27, 2008 Mar 27, 2008
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 27, 2008 Mar 27, 2008
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2008 Mar 27, 2008
Perhaps a step in the right direction.

I now have:

select * from my.table
where startdate > <CFQUERYPARAM VALUE="#01/01/2008#" CFSQLTYPE="CF_SQL_NUMERIC">

Now I get an error of:

[ODBC][Ora]ORA-01847: day of month must be between 1 and last day of month

Tried a few methods of formatting the month, but no dice.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 27, 2008 Mar 27, 2008
Try this.

select * from my.table
where startdate > <CFQUERYPARAM VALUE="01/01/2008" CFSQLTYPE="CF_SQL_TIMESTAMP">

or

select * from my.table
where startdate > <CFQUERYPARAM VALUE="2008-01-01" CFSQLTYPE="CF_SQL_TIMESTAMP">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 27, 2008 Mar 27, 2008
You can use the Oracle to_date() function to convert your string to a date/time object:

select * from my.table
where startdate > to_date('2008-01-01', 'YYYY-MM-DD')

Or, since you are using an ODBC connection to Oracle, you can try using the ColdFusion CreateODBCDate() function:

select * from my.table
where startdate > #CreateODBCDate("2008-01-01")#

Or, as already suggested, use cfqueryparam with the appropriate CFSQLType, such as CF_SQL_TIMESTAMP instead of CF_SQL_INTEGER like you are attempting to do.

You can't use a "string" date value against a date/time column in an Oracle query, as it won't perform an implicit type conversion.

Phil
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2008 Mar 27, 2008
LATEST
Haha, yeah I just noticed that instead of CF_SQL_NUMERIC I should have been using CF_SQL_DATE

Everything is working now for me, thanks for the help, I really appreciate it!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources