Wednesday 19 August 2015

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

Issue: when we create a virtual column with DATE datatype,we should have the proper value for the physical column.
Ex:We created a virtual column X_CAL_WEEK_END_DT based on the physical column CAL_WEEK_END_DT_WID.

CAL_WEEK_END_DT_WID having the date values in the following formate YYYYMMDD.But one value has 0.Without knowing the value of zero(0),we created Virtual column with below script

ALTER TABLE w_day_d ADD x_CAL_WEEK_END_DT GENERATED ALWAYS AS (TO_DATE(TO_CHAR("CAL_WEEK_END_DT_WID"),'yyyymmdd'))  VIRTUAL;

The above alter script can not covert the value ZERO(0) to DATE.

FIX:Changed the alter script like below.
ALTER TABLE w_day_d ADD x_CAL_WEEK_END_DT GENERATED ALWAYS AS (CASE  WHEN "CAL_WEEK_END_DT_WID"<>0 THEN TO_DATE(TO_CHAR("CAL_WEEK_END_DT_WID"),'yyyymmdd') END)  VIRTUAL;



No comments:

Post a Comment