SQL homecontents start chapter top of pagebottom of pagenext page indexSQL Functions

SQL Functions

All SQL functions return a single value that is either a number or a string. Functions may be used anywhere that a value or expression is appropriate. There are two types of functions:

Standard

Aggregation
There is also a special function, EXISTS, which is used to test whether a row is returned by a subquery.


Standard Functions

The expressions in the arguments must be of the correct type (numeric or string) for the function being used. Expressions can contain constants, variables, computations and other functions. Functions can be nested as necessary. Enclose string constants in single quotes. Date, time and categorical variables can be treated as an integer or as a string depending on the context. A specification of one of these variables retains the original data type. However, if these are referred to in a numeric function, the integer value is returned; if referred to in a string function, the string value is returned. Once a variable has been used in a computation or expression in this way, the resulting column is an integer or a string rather than being a date, time or categorical column. SQL eliminates null computations, for example TODAY(0)+0, creating an expression which is equivalent to a simple specification of the variable. For example;

SELECT BIRTHDAY FROM EMPLOYEE
This creates a BIRTHDAY column which is a date:

SELECT BIRTHDAY+365 FROM EMPLOYEE
This creates a "BIRTHDAY+365" column which is an integer. The SQL functions are:

ABS

num = ABS( expression )
ALL
value = ALL ( value_list | subquery )
ANY
value = ANY ( value_list | subquery )

CDATE
num = CDATE ( date-string [, date_map])
CTIME
num = CTIME ( time_string [, time_map ])
DATEC
str = DATEC ( date_integer, date_map)
EXISTS
SELECT .... WHERE EXISTS ( SELECT * ....  )
SELECT .... WHERE NOT EXISTS( SELECT * ....)
INT
num = INT ( expression )
LEN
num = LEN( string )
LOWER
str = LOWER( string )
MAXIMUM
num = MAXIMUM ( value1, value2 )
MINIMUM
num = MINIMUM ( value1, value2 )
MOD
num = MOD ( number, divisor )
NOW
num = NOW (0)
NUM
num = NUM ( string )
NVL
num  =  NVL ( column, arg1, arg2, ...)
str  =  NVL ( column, arg1, arg2, ...)
RECCOUNT
num = RECCOUNT ( rectype )
RND
num = RND ( number [, digits ] )
SBST
str = SBST ( string, start, length )
SIGN
num = SIGN ( number, sign )
TIMEC
str = TIMEC ( time_integer, time_map )
TODAY
num = TODAY (0)
TRIM
str = TRIM ( string )
UPPER
str = UPPER ( string )
VALLAB
str = VALLAB ( column_name )


Aggregation functions

Aggregation functions return a single value for all of the relevant rows processed. See SELECT for the effect aggregation functions have on the SELECT process. The aggregation functions are:

AVG ([UNIQUE] numeric_col)

COUNT ( [ UNIQUE ] col | * )
FIRST ( col)
LAST (col)
MAX (col)
MIN (col)
STD( [ UNIQUE ] numeric_col)
SUM ( [ UNIQUE ] numeric_col )

homecontents start chapter top of pagebottom of pagenext page index