lunes, 9 de mayo de 2022

COALESCE (Oracle SQL)

COALESCE returns the first non-null expr in the expression list. At least one expr must not be the literal NULL. If all occurrences of expr evaluate to null, then the function returns null.

Oracle Database uses short-circuit evaluation. That is, the database evaluates each expr value and determines whether it is NULL, rather than evaluating all of the expr values before determining whether any of them is NULL.

If all occurrences of expr are numeric datatype or any nonnumeric datatype that can be implicitly converted to a numeric datatype, then Oracle Database determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that datatype, and returns that datatype.


You can also use COALESCE as a variety of the CASE expression. For example,


COALESCE (expr1, expr2)


is equivalent to:


CASE WHEN expr1 IS NOT NULL THEN expr1 ELSE expr2 END


Similarly,


COALESCE (expr1, expr2, ..., exprn), for n>=3


is equivalent to:


CASE WHEN expr1 IS NOT NULL THEN expr1 

   ELSE COALESCE (expr2, ..., exprn) END

...


Mas ejemplos en la pagina de la fuente: 

Pagina web de documentación de oracle: 

https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions023.htm


Fuentes.

Artículo:  "COALESCE" Publicado en https://www.youtube.com/ Por Miguel de Lis EL 08 may 2022. Consultado el 09/10/2022.

URL: https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions023.htm

No hay comentarios:

Publicar un comentario