I am trying to convert a nvarchar into a date, but I keep getting this error below
TT_11132 Transformation [Expression] had an error evaluating output column [Run_Date1]. Error message is [<> [TO_DATE]: invalid string for converting to Date ... t:TO_DATE(u:'20190304',u:'MM/DD/YYYY HH24:MI:SS')].
but my function doesn't include a 'MM/DD/YYYY HH24:MI:SS'. Here is my function for reference.
TO_DATE(TO_CHAR(to_date(RUN_DATE),'mmddyyyy'),'mm/dd/yyyy')
Please Help
Thank you
Samik is right, just use the TO_DATE(RUN_DATE, 'YYYYMMDD')
What I'd like to add is some explanation why your function is wrong. So stripping it from innermost:
to_date(RUN_DATE)
Converts the RUN_DATE string to a DATE
trying to guess the format as it has not been given. Let's call the result of it as NewDate
and analyze further:
TO_CHAR(NewDate,'mmddyyyy')
Now this will convert NewDate
to a string in the mmddyyyy
format. Let's call this one as NewString_MMDDYYYY
and see where it gets us. This leaves the final function as:
TO_DATE(NewString_MMDDYYYY,'mm/dd/yyyy')
See the error yet? You tell Informatica to convert NewString_MMDDYYYY
to a date. And you tell the function that it is written in the mm/dd/yyyy
format - which obviously is not being used, as the TO_CHAR function was told to store it in mmddyyyy
.
So, if your input RUN_DATE
is in YYYYMMDD
format, then all you need to do is TO_DATE(RUN_DATE, 'YYYYMMDD')
. If another formati is used by RUN_DATE
, just replace the second argument accordingly.
仅用TO_DATE(RUN_DATE, 'YYYYMMDD')
替换所有内容
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.