about - tech blog -

Wildlink's Technology Blog
An occasionally updated list of informative articles.
Pulled from our internal wiki.
ColdFusion - NVL function
2017-08-16 Edited: 2024-02-24


A very common pattern is to show something else if a given variable is empty/blank/null.


Borrowing from the Oracle nvl function, here's a very simple ColdFusion implementation of nvl. (we just kept the existing name nvl from Oracle because most of the developers were already familiar with it)

It keeps code cleaner and avoids confusing Elvis operators in an already busy view.

string function nvl(required string value1, required string value2) {
    if (trim(arguments.value1) NEQ "") {
        return arguments.value1;
    return arguments.value2;

This is included in our common_utils module available in all 5.5 or newer apps (older apps can find it in the common_utls.cfm file).


    The value is : #nvl(variable1, '--- Not Set ---')#
Back to the Tech Blog
Blog engine: 1.4.0