Built-in functions automate common processes and are identified either as column functions or as scalar functions.> Column functions perform an operation on a column value of each SELECTed row and return one value for all rows.
> Scalar functions can be used to manipulate numbers, strings, and date and time types, as well as retrieve system information. When performing an operation on a column value of each SELECTed row, it returns a value for each row.
Scalar functions can be used in a SELECT, WHERE, or HAVING clause.
Because a scalar function returns a value for each row, it can be included with other SELECTed columns or calculations, but it can not be intermixed with column functions.
A scalar function consists of the function name followed by a pair of parentheses.
Inside the parentheses is an argument which is usually a column name or another scalar function.
The ANSI standard supports a number of useful functions. However, over the years, the various DBMS vendors have implemented functions that were missing from the then existing SQL standards. These functions were developed and implemented differently by each vendor. Eventually, the SQL ANSI standards committees saw a community-wide need for a function and picked a standard which may or may not have matched the vendor’s version. Once the standard had been established, it would normally take several years for the vendors to adopt and implement these new standards. Therefore, each database vendor maintains a large number of their own functions that are outside the scope of the SQL ANSI standards, before the vendor has implemented the new standard. Many of these non-standard functions have been identified in the notes in this course. See the documentation of your vendor’s RDBMS system for details.
Some scalar functions retrieve data from the operating system such as current date, current time, and user ID. These system data functions can be included with normal table queries. When retrieving only systems data, some RDBMS systems do not require a FROM clause, but there are these exceptions:
> For DB2 add the clause FROM SYSIBM.SYSDUMMY1.
> For Oracle add the clause FROM DUAL.
Â
Â
Â