about - tech blog -

Wildlink's Technology Blog
An occasionally updated list of informative articles.
Pulled from our internal wiki.
ColdFusion - NVL function


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.cfm file in all apps.


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