HQL一天一个小技巧:coalesce和nvl函数区别
coalesce 函数
COALESCE函数语法为COALESCE(表达式1,表达式2,...,表达式n),n>=2,此表达式的功能为返回第一个不为空的表达式,如果都为空则返回空值。 注意:所有表达式必须为同一类型或者能转换成同一类型。
CREATE OR REPLACE VIEW v AS
SELECT NULL AS C1, NULL AS C2, 1 AS C3, NULL AS C4, 2 AS C5, NULL AS C6 FROM tmp
UNION ALL
SELECT NULL AS C1, NULL AS C2, NULL AS C3, 8 AS C4, NULL AS C5, 5 AS C6 FROM tmp;
SQL> select * from v;
C1 C2 C3 C4 C5 C6
- - ---------- ---------- ---------- ----------
1
共有 0 条评论