A SQL function is similar to an operator in that it manipulates data items and returns a result. SQL functions differ from operators in the format in which they appear with their arguments. This format allows them to operate on zero, one, two, or more arguments:
function(argument, argument, ...)
If you call a SQL function with an argument of a datatype other than the datatype expected by the SQL function, Oracle implicitly converts the argument to the expected datatype before performing the SQL function. See "Data Conversion".
If you call a SQL function with a null argument, the SQL function automatically returns null. The only SQL functions that do not follow this rule are CONCAT, DECODE, DUMP, NVL, and REPLACE.
SQL functions should not be confused with user functions written in PL/SQL. User functions are described in "User Functions".
In the syntax diagrams for SQL functions, arguments are indicated with their datatypes following the conventions described in "Syntax Diagrams and Notation" in the Preface of this reference.
SQL functions are of these general types:
The two types of SQL functions differ in the number of rows upon which they act. A single-row function returns a single result row for every row of a queried table or view; a group function returns a single result row for a group of queried rows.
Single-row functions can appear in select lists (if the SELECT statement does not contain a GROUP BY clause), WHERE clauses, START WITH clauses, and CONNECT BY clauses.
Group functions can appear in select lists and HAVING clauses. If you use the GROUP BY clause in a SELECT statement, Oracle divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, all elements of the select list must be expressions from the GROUP BY clause, expressions containing group functions, or constants. Oracle applies the group functions in the select list to each group of rows and returns a single result row for each group.
If you omit the GROUP BY clause, Oracle applies group functions in the select list to all the rows in the queried table or view. You use group functions in the HAVING clause to eliminate groups from the output based on the results of the group functions, rather than on the values of the individual rows of the queried table or view. For more information on the GROUP BY and HAVING clauses, see the GROUP BY Clause and the HAVING Clause.
In the sections that follow, functions are grouped by the datatypes of their arguments and return values.
Number functions accept numeric input and return numeric values. This section lists the SQL number functions. Most of these functions return values that are accurate to 38 decimal digits. The transcendental functions COS, COSH, EXP, LN, LOG, SIN, SINH, SQRT, TAN, and TANH are accurate to 36 decimal digits. The transcendental functions ACOS, ASIN, ATAN, and ATAN2 are accurate to 30 decimal digits.
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Syntax |
|
Purpose |
|
|
|
|
|
Syntax |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Example |
|
Purpose |
|
Examples |
|
|
|