Skip to content
Advertisement

Issue in a function that converts a string into a valid date

I have been using this function for last few years that converts an input string into a valid date in decided format.

The above query will return, 28-02-2002 00:58:15

However starting 29/02/2020, if the input string to the function changes to ‘20200229005947354241′, it returns a null! I am not sure if this something related to leap year but not able to figure it out yet.

The function definition is,

I have checked that there is no error as when I checked I received this message “ORA-0000: normal, successful completion”. Please let me know what could be the issue.

Regards, S

Advertisement

Answer

It could be simply done in pure SQL:

Another thing in your code which is really dangerous:

It’s a bug waiting for its chance to break the atomicity of a procedural call. You are hiding the error in your code. Please see WHEN OTHERS – A bug

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