简体   繁体   中英

Are these SQL statements equivalent - case when vs. NVL?

My colleague has the following SQL statement executed in Redshift:

SELECT
    CASE
        WHEN P.PRED_VAL IS NULL THEN R.SCORE_VAL
        ELSE P.PRED_VAL
    END AS FINAL_SCORE
FROM RESULT R
INNER JOIN PREDICTION P
    ON R.ID = P.ID;

Is there any context in which the result of that statement wouldn't be the same as NVL(P.PRED_VAL, R.SCORE_VAL) ?

nvl is simply a non-standard name for the SQL standard coalesce function.

There is no functional difference between your case and your nvl , except that nvl is non-standard. Use coalesce .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM