Categories:

Conditional Expression Functions

REGR_VALX

If the first argument is NULL, returns NULL. Otherwise, returns the second argument.

Contrast REGR_VALX and REGR_VALY with NVL:

  • NVL is a NULL-replacing function.

  • The less commonly used REGR_VALX and REGR_VALY are NULL-preserving functions.

Syntax

REGR_VALY(y, x)

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.

Returns

Returns a value of type DOUBLE.

Examples

SELECT REGR_VALX(NULL, 10), REGR_VALX(1, NULL), REGR_VALX(1, 10);
---------------------+--------------------+------------------+
 REGR_VALX(NULL, 10) | REGR_VALX(1, NULL) | REGR_VALX(1, 10) |
---------------------+--------------------+------------------+
 [NULL]              | [NULL]             | 10               |
---------------------+--------------------+------------------+

This example is similar to the preceding example, but shows more clearly that the convention is to pass the Y value first. This 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);
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 |
+-------+-------+-------------------------+-------------------------+