Getting error while running session as not avalid month

Viewed 25

I have a oracle view in which we have column called dayofset which defined from subtraction of two date columns like(to_date(date_column1)-to_date(date_column2)) and it is stored as number(38) datatype. 2.so,when I run session in informatica to get data from oracle view to redshift.im getting error like "not a valid month". 3.Input values for that column is like (25-JAN-21,10-APR-13) 4.im getting the output values like 1,2,3,4... Like this all are integer values.(this column just do the datediff operation) and provide the difference between two dates.

Could you guys please help on this.

1 Answers

I have a oracle view in which we have column called dayofset which defined from subtraction of two date columns like to_date(date_column1)-to_date(date_column2) and it is stored as number(38) datatype.

Never use TO_DATE on a column that is already a DATE data type. Just use.

CREATE VIEW your_view (dayofset)
SELECT date_column1 - date_column2
FROM   your_table;

If you use TO_DATE then it takes a string as the first argument so you are effectively performing an implicit conversion to a string to convert it back to a date and your code is the equivalent of:

CREATE VIEW your_view (dayofset)
SELECT TO_DATE(
         TO_CHAR(
           date_column1,
           (SELECT value FROM NLS_SESSION_PARAMETERS WHERE parameter = 'NLS_DATE_FORMAT')
         ),
         (SELECT value FROM NLS_SESSION_PARAMETERS WHERE parameter = 'NLS_DATE_FORMAT')
       )
       -
       TO_DATE(
         TO_CHAR(
           date_column2,
           (SELECT value FROM NLS_SESSION_PARAMETERS WHERE parameter = 'NLS_DATE_FORMAT')
         ),
         (SELECT value FROM NLS_SESSION_PARAMETERS WHERE parameter = 'NLS_DATE_FORMAT')
       )
FROM   your_table;

Depending on your NLS_DATE_FORMAT session parameter, this could just be a waste of time or it could truncate the date and give you an unexpected result; however, any user can change their session parameters at any time so you may get different results for different users so you should NEVER rely on implicit conversions.


If your columns are not a DATE data-type but are strings then use an explicit format model (and, if required, language) in the conversion:

CREATE VIEW your_view (dayofset)
SELECT TO_DATE(string_column1, 'DD-MON-RR', 'NLS_DATE_LANGUAGE=English')
       - TO_DATE(string_column2, 'DD-MON-RR', 'NLS_DATE_LANGUAGE=English')
FROM   your_table;
Related