OracleCommand seems to convert literal dates
I built a small query tool for Oracle using OracleCommand and OracleDataAdapter. Users just input a full query (no parameters), execute and the results are shown in a datagridview. So far so good, although I tried an invalid query, e.g.:
SELECT * FROM mytable WHERE dateColumn = '1-JAN-10'
This query is not valid SQL for Oracle. You have to use the to_date() function to compare with date literals. SQL developer also rejects it, but somehow my query tool just works. Does that mean my OracleCommand is a bit of a wizard here or am I doing something wrong? Also is there a way to omit this behavior because the purpose o开发者_JS百科f the tool is testing queries, which should work always...
Thanks
The query may be valid for Oracle. You don't have to use to_date()
if you give the date string in your session's date format, though it's generally better to do that anyway to avoid issues like this.
It sounds like you have a different NLS_DATE_FORMAT
in your tool's environment to that in SQL Developer, or the session date format is being set implicitly by OracleCommand.
You can select value from nls_session_parameters where parameter = 'NLS_DATE_FORMAT'
to see what it is from SQL*Plus and SQL Developer, and from your tool; and from nls_database_parameters
to see which is overriding the database default.
Looks like your tool may have DD-MON-RR
and you're expecting some other format elsewhere, but without checking those tables it's hard to say where you're using the database default and where you're overriding it at session level. I'd guess that is the DB default though and you have an override in your other environments.
From SQL Developer, try alter session set nls_date_format='DD-MON-RR';
and then re-run your invalid query - should work there too.
精彩评论