Thanks for answer.
Is correct, the default setting for date format in Database is 'DD-MON-YY'.
But it's setting was like this and previous version Toad my sentence working.
I understand is better put format.
Very thanks for all.
--
Luis E. Hernández Manzanares
Soporte Sistemas de Gestión
**Sociedad Suizo Peruana ****de ****Embutidos S.A. **
SUPEMSA
Comunidad Industrial 240 - Chorrillos
Central: (51) 1 336-7000 Anexo: 1248
Celular: (51) 998 106 098
Atención de Soporte Técnico y Sistemas y Procedimientos de Sistemas
2017-10-18 7:37 GMT-05:00 Norm [TeamT] bounce-NormTeamT@toadworld.com:
RE: Format for date query
Reply by Norm [TeamT]
Afternoon All,
If you run a query such as your first one, in Toad, it is the database that does the execution, Toad simply passes what you ask to execute to the database. So, when you execute
select * from my_table where campo_fecha >= to_date('01/10/2017');
Oracle will convert the passed string literal '01/10/2017' to a date using your user's default NLS_DATE_FORMAT string - and it is possible that the default for the database has been changed since you upgraded Toad. You, as a developer (I assume) have no control over what your DBAs do with default database parameters. All my databases, for example, were always set to 'dd/mm/yyyy hh24:mi:ss' as the default for the database. If people wanted to change that, they had to execute an alter session set nls_date_format=whatever; - and that assumed that they had been granted alter session privileges.
So, you need to find out what your database's default NLS_DATE_FORMAT has been set to. On the other hand, Oracle will try to convert string literals, as above, using the default format, but will then attempt to convert it using some other (unknown) formats until it finds one that works, or, they all fail. So, the above date string could be converted as 1st October 2017 00:00:00 or 10th January 2017 00:00:00 if the USA's default date format of mm/dd/yyyy takes precedence over whatever other formats are used by Oracle to convert a date string like yours, where no required format has been supplied.
So, the question has to be, what is the database converting your string to as a date? October or January?
select * from nls_session_parameters where parameter = 'NLS_DATE_FORMAT';
Will show you the default date format for your session, if you have access to NLS_SESSION_PARAMETERS that is.
So, back to your date string, January or October? How to tell?
In a database with the date format set to 'DD-MON-RR' I get an error telling me that 10 is not a valid month. Makes sense, however, Oracle seems to have failed to convert the string to a date.
In a database where I have set my default to be 'dd/mm/yyyy hh24:mi:ss', I get no errors, and select to_date('01/10/2017') from dual; gives me exactly that, '01/10/2017 00:00:00' so it appears to be October, for me at least. Better check though:
If I now select to_char(to_date('01/10/2017'), 'dd-Month-yyyy') from dual; then I get, as expected, '01-October -2017' so it's converting correctly and not attempting to go down the route of the USA's much favoured but extremely weird date format!
So, do you see the problem here? You don't know what the DBAs have set up as the default date format, and you are assuming/expecting it to be something that all your dates will convert with - which might not always be the case. My advice to you, and always has been to any developers I've worked with, is to always be explicit as you never know when things might change underneath you, without you knowing. You should therefore always tell TO_DATE() exactly what format your date strings are in, so that it (a) doesn't have to guess and (b) shouldn't raise any errors for certain dates that you pass.
Is it possible therefore that your DBAs have changed something? Did they upgrade the database perhaps to a new version? Did they apply a patch perhaps? Has some other application started using the database, and has required a default date format change?
There are numerous ways that we DBAs can seriously mess up developers' lives, without even trying! If you are always explicit in your date strings and tell TO_DATE() exactly what format the strings are in, then nothing we DBAs can do will upset your code. If you don't want to always be explicit, then try running something like alter session set nls_date_format='dd/mm/rrrr' (which seems to be what you want - but beware of any time portions in your date literals if you do) and then you don't have to tell TO_DATE() the required format, it will use your session default of 'DD/MM/RRRR' or whatever you set.
Finally, there are rows in my_table where campo_fecha is indeed greater than or equal to 1st October 2017? Because you didn't mention that your execution of the statement was giving an error, so Oracle must have converted the string to a date, of some kind, and compared it with the column. Try running the statement(s) in SQL*Plus and check if you get a message like 'no rows returned' which would indicate a table with no rows matching your date. Equally, in Toad, go to Database->Spool SQL -> to screen then execute the failing statement again. At the bottom of the screen you will see exactly what Toad sent to Oracle to be executed, and what happened to it when it got there.
Have fun.
HTH.
To reply, please reply-all to this email.
Stop receiving emails on this subject.
Or Unsubscribe from Toad for Oracle Forum notifications altogether.
Toad for Oracle - Discussion Forum
Flag this post as spam/abuse.
Aviso de Confidencialidad y Protección de Datos Personales:
Este correo electrónico y/o el material adjunto es para uso exclusivo de la persona o entidad a la que expresamente se le ha enviado, y puede contener información confidencial y/o material privilegiado y/o protegido por la Ley de Protección de Datos Personales. Si usted es el destinatario legítimo del mismo, adicionalmente le indicamos que toda la información que nos brinde y que se considere como “datos personales” y/o “datos sensibles” según lo dispuesto en la Ley de Protección de Datos Personales, serán tratados de manera reservada y confidencial conforme lo establece la referida Ley y nuestro marco constitucional (Dar “click” para leer condiciones y “ACEPTAR” o “NO ACEPTAR” las mismas previamente leídas). Si usted no es el destinatario legítimo del mismo, por favor repórtelo inmediatamente al remitente del correo y bórrelo. Cualquier revisión, retransmisión, difusión o cualquier otro uso de este correo, por personas o entidades distintas a las del destinatario legítimo, queda expresamente prohibido. Este correo electrónico no pretende ni debe ser considerado como constitutivo de ninguna relación legal, contractual o de otra índole similar, en consecuencia, no genera obligación alguna a cargo de su emisor o su representada. En tal sentido, nada de lo señalado en esta comunicación o en sus anexos podrá ser interpretado como una recomendación sobre los riesgos o ventajas económicas, legales, contables o tributarias, o sobre las consecuencias de realizar o no determinada transacción. Este correo electrónico y/o el material adjunto deben contener información de carácter institucional, vinculada a las labores del remitente, en caso no tenga(n) dicha condición, el mismo es de exclusiva responsabilidad del remitente, sin responsabilidad alguna para Sociedad Suizo Peruana de Embutidos S.A. - SUPEMSA”.