Skip to content
Advertisement

TO_CHAR failing to set specific format in update

I’m trying to set a specific field in a record where the legacy code has used a DDMM format DATETIME as a char. I want to be able to find one specific value that matches something and basically change that one field. Super simple stuff, right?

I know for a fact that if I query using to_char(SOME_DATETIME, ‘DDMM’) = ‘0311’ in a where clause it works but I can’t seem to be able to get to change that field. I get the following error:

I’ve found plenty of examples where people have overcome this error message in a query but not in a “set”.

I’m new at Oracle so would love some help.

Thanks

Advertisement

Answer

It seems the data type of SOME_DATETIME is DATE, since query works for to_char(SOME_DATETIME, 'DDMM') = '0311' conversion. Then proper to use the following :

where the true conversion should be performed by to_date instead of to_char.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement