Categories:

Conditional expression functions

REGR_VALY

Returns NULL if the second argument is NULL; otherwise, returns the first argument.

Note that REGR_VALY is a NULL-preserving function, while the more commonly-used NVL is a NULL-replacing function.

Syntax

REGR_VALY( <y> , <x> )
Copy

Arguments

y:

An expression that evaluates to type DOUBLE or that can be cast to DOUBLE.

x:

An expression that evaluates to type DOUBLE or that can be cast to DOUBLE.

Important

Note the order of the arguments; y precedes x.

Returns

Returns a value of type DOUBLE.

Examples

Basic example:

SELECT REGR_VALY(NULL, 10), REGR_VALY(1, NULL), REGR_VALY(1, 10);
+---------------------+--------------------+------------------+
| REGR_VALY(NULL, 10) | REGR_VALY(1, NULL) | REGR_VALY(1, 10) |
|---------------------+--------------------+------------------|
|                NULL |               NULL |                1 |
+---------------------+--------------------+------------------+
Copy

This example is similar to the preceding example, but shows more clearly that the convention is to pass the Y value first. It also shows the difference between REGR_VALX and REGR_VALY:

CREATE TABLE xy (col_x DOUBLE, col_y DOUBLE);
INSERT INTO xy (col_x, col_y) VALUES
    (1.0, 2.0),
    (3.0, NULL),
    (NULL, 6.0);
Copy
SELECT col_y, col_x, REGR_VALX(col_y, col_x), REGR_VALY(col_y, col_x)
    FROM xy;
+-------+-------+-------------------------+-------------------------+
| COL_Y | COL_X | REGR_VALX(COL_Y, COL_X) | REGR_VALY(COL_Y, COL_X) |
|-------+-------+-------------------------+-------------------------|
|     2 |     1 |                       1 |                       2 |
|  NULL |     3 |                    NULL |                    NULL |
|     6 |  NULL |                    NULL |                    NULL |
+-------+-------+-------------------------+-------------------------+
Copy