Sometimes I see an nvl()
function in code. In the case of Java, it looks like this:
public static String nvl(String value, String alternateValue) {
if (value == null)
return alternateValue;
return value;
}
I understand what this function does, but I don't understand why it's called nvl
. Why not checkNotNull
or returnNotNull
? What does NVL stand for?
I guess Null Value L...?
string val = value != null ? value : alternative
. Besides, in a function call, both values are evaluated firstly than the function call, this can lead to programming mistakes, I actually see this happen very often. Prefer ternary operator – Gerber