Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORA-01840: input value not long enough for date format

epipkoJul 22 2021 — edited Jul 22 2021

Hi,
Oracle 19.3 on Win2019
I am running the following query and receiving ORA-01840.
The t-year is 2022. The date format in case statement comes out as "1/1/2022".
Why am I getting this error and how do I fix it?

select  case n
      when 1 then to_date('01/01/'||''||t_year||'','mm/dd/yyyy')
      when 2 then to_date('02/01/'||''||t_year||'','mm/dd/yyyy')
      when 3 then to_date('03/01/'||''||t_year||'','mm/dd/yyyy')
      when 4 then to_date('04/01/'||''||t_year||'','mm/dd/yyyy')
      when 5 then to_date('05/01/'||''||t_year||'','mm/dd/yyyy')
      when 6 then to_date('06/01/'||''||t_year||'','mm/dd/yyyy')
      when 7 then to_date('07/01/'||''||t_year||'','mm/dd/yyyy')
      when 8 then to_date('08/01/'||''||t_year||'','mm/dd/yyyy')
      when 9 then to_date('09/01/'||''||t_year||'','mm/dd/yyyy')
      when 10 then to_date('10/01/'||''||t_year||'','mm/dd/yyyy')
      when 11 then to_date('11/01/'||''||t_year||'','mm/dd/yyyy')
      when 12 then to_date('12/01/'||''||t_year||'','mm/dd/yyyy')
    end x
from T

cross join

 select 1 n from dual
 union all
 select 2 from dual
 union all
 select 3 from dual
 union all
 select 4 from dual
 union all
 select 5 from dual
 union all
 select 6 from dual
 union all
 select 7 from dual
 union all
 select 8 from dual
 union all
 select 9 from dual
 union all
 select 10 from dual
 union all
 select 11 from dual
 union all
 select 12 from dual

 );
This post has been answered by BluShadow on Jul 23 2021
Jump to Answer

Comments

Post Details

Added on Jul 22 2021
12 comments
10,243 views