The Daily WTF
Today, we look at a simple bit of bad code. The badness is not that they’re using Oracle, though that’s always bad. But it’s how they’re writing this PL/SQL stored function:
FUNCTION CONVERT_STRING_TO_DATE –Public (p_date_string IN Varchar2, p_date_format IN Varchar2 DEFAULT c_date_format) Return Date AS BEGIN If p_date_string Is Null Then Return Null; Else Return To_Date(p_date_string, p_date_format); End If; END; — FUNCTION CONVERT_STRING_DATE
This code is a wrapper around the to_date function. The to_date function takes a string and a format and returns that format as a date.
This wrapper adds two things, and the first is a null check. If the input string is null, just return null. Except that’s exactly how to_date behaves anyway.
The second is that it sets the default format to c_date_format. This, actually, isn’t a terrible thing. If you check the docs on the function, you’ll see that if you don’t supply
To read the full article click on the 'post' link at the top.