TO_DATE( date_string, format_model )
Takes a string as its first argument. Assuming paydate
is a DATE
data type then you are asking Oracle to implicitly convert paydate
from a DATE
to a string (which will use the NLS_DATE_FORMAT
session parameter) and then to pass it into the TO_DATE
function to convert it back to a date.
So, your query is effectively:
SELECT *
FROM <old_table_name>
WHERE paydate =TO_DATE(
TO_CHAR(
paydate,
( SELECT value FROM NLS_SESSION_PARAMETERS WHERE parameter = 'NLS_DATE_FORMAT' )
),
'YYYYMMDD'
);
If the NLS_DATE_FORMAT
does not match YYYYMMDD
then you will either get an exception or unexpected behaviour.
Instead, if you want to compare a date to itself and find out if its time component is at midnight then just use TRUNC
:
SELECT *
FROM <old_table_name>
WHERE paydate = TRUNC( paydate );