SQL> select to_date(' ','YYYYMMDD') from dual;
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, not be 0
SQL> select * from dual where to_date(' ','YYYYMMDD') = '19960512' or 1 = 2;
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, not be 0
SQL> select * from dual where to_date(' ','YYYYMMDD') = '19960512' or 1 = 1;
Success.
In first two statements we are passing spaces to TO_DATE function which gives an error which is expected. But
Now in third statement we are passing spaces to TO_DATE oracle function which is not allowed. But still it executes successfully.
Why?
In actual code I might pass spaces from variable and OR part may or may not be true.
Can anyone explain me this behaviour and how to handle to get an error?
P.S - I am on Oracle 12g EE