Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: apply rtrim on DATE data
ouyang.jie_at_gmail.com wrote:
> Hi All,
> The sql below does not return anything,
> select DTE_SYSDATE
> from A_T_PR_TAXONOMY
> WHERE DTE_SYSDATE = to_date( 20071031, 'yyyymmdd')
>
> while these two return some rows
> select DTE_SYSDATE
> from A_T_PR_TAXONOMY
> WHERE rtrim(DTE_SYSDATE) = to_date( 20071031, 'yyyymmdd')
>
> select DTE_SYSDATE
> from A_T_PR_TAXONOMY
> WHERE DTE_SYSDATE LIKE to_date( 20071031, 'yyyymmdd')
>
>
> results:
> 31-OCT-07
> 31-OCT-07
> 31-OCT-07
> 31-OCT-07
>
> DTE_SYSDATE is a DATE type field in the table A_T_PR_TAXONOMY. I am
> confused at why the rtrim can make this difference.
Things work better when done according to the docs:
Do the following in SQL*Plus:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS'; whenever working with dates so you can see what is actually going on.
Best practice is to use TRUNC. Look at the last TRUNC demos here near page bottom. http://www.psoug.org/reference/date_func.html
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace x with u to respond) Puget Sound Oracle Users Group www.psoug.orgReceived on Thu Nov 01 2007 - 15:44:33 CDT