sábado, 9 de julio de 2022

Oracle GREATEST and LEAST Function

The Oracle GREATEST function and LEAST function are quite useful, but not very well understood. Let’s take a look at these functions and see some examples in this article.


Purpose of the Oracle GREATEST and LEAST Function


The Oracle GREATEST function returns the “greatest” or largest value in a set of values that you provide to it.

The Oracle LEAST function returns the “least” or smallest value in a set of values that you provide to it, and it’s the opposite of the GREATEST function.


In both functions, you can use numbers as well as text values.


Oracle GREATEST Function Syntax and Parameters


The syntax for the Oracle GREATEST function is:


GREATEST ( expr1, [expr_n] )


The parameters of the function are:


expr1 (mandatory): This is the first expression to use for comparison.

expr_n (optional): This is one or more expressions, separated by commas, to use in a comparison.

 


Oracle LEAST Function Syntax and Parameters


The syntax for the Oracle LEAST function is:


LEAST ( expr1, [expr_n] )


The parameters of this function are:


expr1 (mandatory): This is the first expression to use for comparison.

expr_n (optional): This is one or more expressions, separated by commas, to use in a comparison.


What Datatype Is Returned By Oracle GREATEST or Oracle LEAST?


The Oracle GREATEST and LEAST functions return datatype depends on a few factors:


If the data types of the expressions are different, GREATEST will convert them to the same data type as expr1.

All of the expressions are converted to the same data type before the first comparison is done.

If any of the expressions are NULL, then GREATEST will return NULL.

The return data type is VARCHAR2 if all values are character values.

 


Can You Use GREATEST or LEAST with a DATE?


Yes, you can. It works in a similar way to other data types. It finds the earliest occurring date.


Fuentes.

Artículo:  "Oracle GREATEST and LEAST Function Guide, FAQ, & Examples" Publicado en https://www.databasestar.com/ . Consultado el 26/06/2022.

URL: https://www.databasestar.com/oracle-greatest/#:~:text=The%20Oracle%20LEAST%20function%20returns,as%20well%20as%20text%20values.


No hay comentarios:

Publicar un comentario