8

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...?

c0rp
  • 501
  • 1
  • 10
  • 31
  • 4
    It's **N**ull **V**a**L**ue or **N**ull **V**alue **L**ogic according to [this](http://www.abbreviations.com/term/157605) – Duffydake Mar 09 '15 at 06:03
  • I vote **N**ull **V**a**L**ue – shmosel Mar 09 '15 at 06:04
  • 2
    As far as I know NVL stand for Null VaLue. I think it keep the standards of SQL which was a well versed function for database developers. Moreover we are not returning any boolean value to name the method name as isNull() or checkNull() something like that. – HJK Mar 09 '15 at 06:16
  • its simply Null Value – Prashant Mar 09 '15 at 06:25
  • This function is sub-optimal for languages like java, in which you have have the following construction: `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 – EProgrammerNotFound Mar 11 '15 at 03:57
  • also because nvl exists in some languages, like oracle PLSQL – Adam Silenko Aug 26 '19 at 07:11

1 Answers1

10

As others have pointed out in comments, it probably stands for "null value" or "null value logic". It might just as well be called "dflt" (or similar abbreviation) for "default".

And, in Java, it should really be using generics so that it can work on any type ;)

Atsby
  • 2,277
  • 12
  • 14