Skip to main content

NVL2

Introduced or updated: v1.2.312

Returns <expr2> if <expr1> is not NULL; otherwise, it returns <expr3>.

Syntax

NVL2(<expr1> , <expr2> , <expr3>)

Examples

SELECT NVL2('a', 'b', 'c'), NVL2(NULL, 'b', 'c');

┌────────────────────────────────────────────┐
│ nvl2('a', 'b', 'c') │ nvl2(null, 'b', 'c')
├─────────────────────┼──────────────────────┤
│ b │ c │
└────────────────────────────────────────────┘

SELECT NVL2(1, 2, 3), NVL2(NULL, 2, 3);

┌──────────────────────────────────┐
│ nvl2(1, 2, 3) │ nvl2(null, 2, 3)
├───────────────┼──────────────────┤
23
└──────────────────────────────────┘
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today