Common Functions A-C D-G H-L M-Q R-Z Trigonometric functions
SQL-99 Scalar abs ( numeric_expression ) Returns the absolute value of "numeric_expression". Negative values are returned as positive values. Example: abs ( 15 ) Result: 15 Example: abs ( -15 ) Result: 15 bit_length bit_length ( string_expression ) Returns the number of bits in "string_expression". cast ( expression , datatype_specification ) Converts "expression" to a specified data type. Some data types allow for a length and precision to be specified. Make sure that the target is of the appropriate type and size. The following can be used for "datatype_specification": character, varchar, char, numeric, decimal, integer, bigint, smallint, real, float, date, time, timestamp, time with time zone, timestamp with time zone, and interval. When type casting to an interval type, one of the following interval qualifiers must be specified: year, month, or year to month for the year-to-month interval datatype; day, hour, minute, second, day to hour, day to minute, day to second, hour to minute, hour to second, or minute to second for the day-to-second interval datatype. Notes: When you convert a value of type timestamp to type date, the time portion of the timestamp value is ignored. When you convert a value of type timestamp to type time, the date portion of the timestamp is ignored. When you convert a value of type date to type timestamp, the time components of the timestamp are set to zero. When you convert a value of type time to type timestamp, the date component is set to the current system date. It is invalid to convert one interval datatype to the other (for instance because the number of days in a month is variable). Note that you can specify the number of digits for the leading qualifier only, i.e. YEAR(4) TO MONTH, DAY(5). Errors will be reported if the target type and size are not compatible with the source type and size. Example: cast ( '123' , integer ) Result: 123 Example: cast ( 12345 , varchar ( 10 ) ) Result: a string containing 12345 char_length ( string_expression ) Returns the number of logical characters in "string_expression". The number of logical characters can be distinct from the number of bytes in some East Asian locales. Example: char_length ( 'Canada' ) Result: 6 character_length ( string_expression ) Returns the number of characters in "string_expression". Example: character_length ( 'Canada' ) Result: 6 current_date current_date Returns a date value representing the current date of the computer that the database software runs on. Example: current_date Result: 2003-03-04 current_time current_time Returns a time with time zone value, representing the current time of the computer that runs the database software if the database supports this function. Otherwise, it represents the current time of the computer that runs IBM® Cognos® BI software. Example: current_time Result: 16:33:11.354+05:00 current_timestamp current_timestamp Returns a datetime with time zone value, representing the current time of the computer that runs the database software if the database supports this function. Otherwise, it represents the current time of the computer that runs IBM® Cognos® BI software. Example: current_timestamp Result: 2003-03-03 16:40:15.535+05:00 localtime localtime Returns a time value, representing the current time of the computer that runs the database software. Example: localtime Result: 16:33:11 localtimestamp localtimestamp Returns a datetime value, representing the current timestamp of the computer that runs the database software. Example: localtimestamp Result: 2003-03-03 16:40:15 extract ( datepart , datetime_expression ) Returns an integer representing the value of datepart (year, month, day, hour, minute, second, epoch) in "datetime_expression". Example: extract ( year , 2003-03-03 16:40:15.535 ) Result: 2003 Example: extract ( hour , 2003-03-03 16:40:15.535 ) Result: 16 Example: extract ( epoch , 2014-11-23 ) Result: 1416718800 lower ( string_expression ) Returns "string_expression" with all uppercase characters shifted to lowercase. Example: lower ( 'ABCDEF' ) Result: abcdef mod ( integer_expression1, integer_expression2 ) Returns the remainder (modulus) of "integer_expression1" divided by "integer_expression2". "Integer_expression2" must not be zero or an exception condition is raised. Example: mod ( 20 , 3 ) Result: 2 occurrences_regex ( regex_expression , string_expression [ , integer_expression [ , flags_expression ]] ) Returns the integer value representing the number of occurrences of the regular expression "regex_expression" in "string_expression". The search starts at position "integer_expression", which has a default value of 1. Flags to set options for the interpretation of the regular expression are specified by "flags_expression". Individual letters are used to define the flags, with valid values being 's', 'm', 'i', and 'x'. Example: occurrences_regex ( '.er' , 'Flicker Lantern') Result: 2 octet_length ( string_expression ) Returns the number of bytes in "string_expression". Example: octet_length ( 'ABCDEF' ) Result: 6 Example: octet_length ( '' ) Result: 0 position ( string_expression1 , string_expression2 ) Returns the integer value representing the starting position of "string_expression1" in "string_expression2" or 0 when the "string_expression1" is not found. Example: position ( 'C' , 'ABCDEF' ) Result: 3 Example: position ( 'H' , 'ABCDEF' ) Result: 0 position_regex ([ start|after ]  regex_expression , string_expression [ , integer_expression1 [ , integer_expression2 [ , flags_expression ]]] ) Returns the integer value representing the beginning or ending position of the substring in "string_expression" that matches the regular expression "regex_expression". The search starts at position "integer_expression1", which has a default value of 1. The occurrence of the pattern to search for is specified by "integer_expression2", which has a default value of 1. The return option, specified by the first argument, specifies what is returned in relation to the occurrence. If you specify "start", the position of the first character of the occurrence is returned. If you specify "after", the position of the character following the occurrence is returned. If you don't specify a return option, "start" is implicit. Flags to set options for the interpretation of the regular expression are specified by "flags_expression". Individual letters are used to define the flags, with valid values being 's', 'm', 'i', and 'x'. Example: position_regex ( '.er' , 'Flicker Lantern') Result: 5 Example: position_regex ( after '.er' , 'Flicker Lantern' ) Result: 8 Example: position_regex ( '.er' , 'Flicker Lantern' , 1 , 2 ) Result: 12 trim ( [ [ trailing|leading|both ] [ match_character_expression ] , ] string_expression ) Returns "string_expression" trimmed of leading and trailing blanks or trimmed of a certain character specified in "match_character_expression". "Both" is implicit when the first argument is not stated and blank is implicit when the second argument is not stated. Example: trim ( trailing 'A' , 'ABCDEFA' ) Result: ABCDEF Example: trim ( both , ' ABCDEF ' ) Result: ABCDEF upper ( string_expression ) Returns "string_expression" with all lowercase characters converted to uppercase. Example: upper ( 'abcdef' ) Result: ABCDEF user user Returns an authorization ID to database manager at runtime. nullif nullif ( expression1, expression2 ) Returns null if "expression1" equals "expression2", otherwise returns "expression1". coalesce ( expression_list ) Returns the first non-null argument (or null if all arguments are null). Requires two or more arguments in "expression_list". coalesce ( [Unit price], [Unit sale price] ) Result: Returns the unit price, or the unit sale price if the unit price is null. coalesce ( expression_list ) Returns the first non-null argument (or null if all arguments are null). Requires one or more arguments in "expression_list". coalesce ( [Unit price], [Unit sale price] ) Result: Returns the unit price, or the unit sale price if the unit price is null. ceil ( numeric_expression ) Returns the smallest integer that is greater than or equal to "numeric_expression". ceiling ( numeric_expression ) Returns the smallest integer that is greater than or equal to "numeric_expression". Example: ceiling ( 4.22 ) Result: 5 Example: ceiling ( -1.23 ) Result: -1 ln ( numeric_expression ) Returns the natural logarithm of "numeric_expression". Example: ln ( 4 ) Result: 1.38629 exp ( numeric_expression ) Returns 'e' raised to the power of "numeric_expression". The constant 'e' is the base of the natural logarithm. Example: exp ( 2 ) Result: 7.389056 period ( datetime_expression1 , datetime_expression2 ) Constructs a period value with a starting point of "datetime_expression1" and an end point of "datetime_expression2". The data types of the start and end points must be identical, and can be one of date, time, or dateTime. Period values can be used in period predicates. Example: period ( 2003-03-03 , 2003-10-03 ) Example: period ( 12:00:00 , 23:59:59 ) Example: period ( 2003-03-03 12:00:00 , 2003-10-03 23:59:59 ) Example: period ( [EMP].[BUS_START] , [EMP].[BUS_END] ) power ( numeric_expression1 , numeric_expression2 ) Returns "numeric_expression1" raised to the power "numeric_expression2". If "numeric_expression1" is negative, then "numeric_expression2" must result in an integer value. Example: power ( 3 , 2 ) Result: 9 random ( [ integer_expression ] ) Returns a random float value between 0 and 1, using the optional "integer_expression" as a seed value. _round ( numeric_expression , integer_expression ) Returns "numeric_expression" rounded to "integer_expression" places to the right of the decimal point. Notes: "integer_expression" must be a non-negative integer. Rounding takes place before data formatting is applied. Example: _round ( 1220.42369, 2 ) Result: 1220.42 The row constructor represents a collection of values organized as a row of data. It can be used in conditional expressions (i.e. IF-THEN-ELSE) and filter expressions (i.e. IN clause). row ( expression_list ) Example: if ( row([RetailerName],[OrderMethodCode]) = row('ActiForme',4) ) then ('A') else ('B') Result: Returns 'A' if the Retailer Name is 'ActiForme' and the order method code is 4. Otherwise, the value 'B' is returned. Example: case row([RetailerName],[OrderMethodCode]) when row('Advanced Climbing Ltd',3) then 1 when row('ActiForme',5) then 2 else 3 end Result: Returns 1 if the Retailer Name is 'Advanced Climbing Ltd' and the order method code is 3. Returns 2 if the Retailer Name is 'ActiForme' and the order method code is 5. Otherwise, the value 3 is returned. Example: row ( [OrderMethodCode], [Year] ) in ( [Query].[OMC], [Query].[YR] ) Result: The returned data is filtered on the following two conditions: 1) [OrderMethodCode] in ([Query].[OMC]) 2) [Year] in ([Query].[YR]) sqrt ( numeric_expression ) Returns the square root of "numeric_expression". "Numeric_expression" must be non-negative. Example: sqrt ( 9 ) Result: 3 substring ( string_expression , integer_expression1 [ , integer_expression2 ] ) Returns the substring of "string_expression" that starts at position "integer_expression1" for "integer_expression2" characters or to the end of "string_expression" if "integer_expression2" is omitted. The first character in "string_expression" is at position 1. Example: substring ( 'abcdefg' , 3 , 2 ) Result: cd substring_regex ( regex_expression , string_expression [ , integer_expression1 [ , integer_expression2 [ , flags_expression ]]] ) Returns a substring of "string_expression" that matches the regular expression "regex_expression". The search starts at position "integer_expression1", which has a default value of 1. The occurrence of the pattern to search for is specified by "integer_expression2", which has a default value of 1. Flags to set options for the interpretation of the regular expression are specified by "flags_expression". Individual letters are used to define the flags, with valid values being 's', 'm', 'i', and 'x'. Example: substring_regex ( '.er' , 'Flicker Lantern') Result: ker Example: substring_regex ( '.er' , 'Flicker Lantern' , 1 , 2 ) Result: ter floor ( numeric_expression ) Returns the largest integer that is less than or equal to "numeric_expression". Example: floor ( 3.22 ) Result: 3 Example: floor ( -1.23 ) Result: -2 width-bucket ( numeric_expression ,  min_value ,  max_value ,  num_of_buckets ) For a given expression, this function returns the bucket number into which the value of this expression would fall after being evaluated. Example: width-bucket ( Quantity ,  100 ,  5000 ,  10 ) Result: For each row, returns the bucket number (from 0 to 11) for the current Quantity value. Quantity width-bucket (Quantity) ------------ ------------------------------------- 50 0 450 1 1400 3 3600 8 4900 10 5000 11 sin ( numeric_expression ) This trigonometric function returns the sine of the argument, where the argument is an angle expressed in radians. Example: sin ( 0.1667 * 3.1415 ) Result: 0.5 cos ( numeric_expression ) This trigonometric function returns the cosine of the argument, where the argument is an angle expressed in radians. Example: cos ( 0.3333 * 3.1415 ) Result: 0.5 tan ( numeric_expression ) This trigonometric function returns the tangent of the argument, where the argument is an angle expressed in radians. Example: tan ( 0.25 * 3.1415 ) Result: 1 arccos ( numeric_expression ) This inverse trigonometric function returns the arc cosine of the argument, where the argument is in the range of -1 to 1 and the result is a value expressed in radians. Example: arccos ( -1 ) Result: 3.1415 arcsin ( numeric_expression ) This inverse trigonometric function returns the arc sine of the argument, where the argument is in the range of -1 to 1 and the result is a value expressed in radians. Example: arcsin ( 0 ) Result: 3.1415 This inverse trigonometric function returns the arc tangent of the argument, where the argument is in the range of -1 to 1 and the result is a value expressed in radians. arctan ( numeric_expression ) Example: arctan ( 0 ) Result: 3.1415 coshyp ( numeric_expression ) This trigonometric function returns the hyperbolic cosine of the argument, where the argument is an angle expressed in radians. Example: coshyp ( 0 ) Result: 1 sinhyp ( numeric_expression ) This trigonometric function returns the hyperbolic sine of the argument, where the argument is an angle expressed in radians. Example: sinhyp ( 0 ) Result: 0 tanhyp ( numeric_expression ) This trigonometric function returns the hyperbolic tangent of the argument, where the argument is an angle expressed in radians. Example: tanhyp ( 0 ) Result: 0
SQL-99 OLAP Extensions cube cube ( grouping_column_reference_list ) This is a 'group by' clause that results in a grouping set list that contains a grouping set for all possible combinations of the grouping columns in "grouping_column_reference_list". rollup rollup ( grouping_column_reference_list ) This is a 'group by' clause that results in a grouping set list that contains a grouping set for every proper sublist of "grouping_column_reference_list" by dropping elements from the right, one by one. grouping sets grouping sets ( grouping_set_list ) This is a 'group by' clause that specifies multiple sets to group by. rank rank () Computes the rank of the row within the window partition, where the rank of row x is defined as 1 plus the number of rows that precede x but are not peers of x. dense_rank dense_rank () Computes the dense rank of the row within the window partition, where the dense rank of row x is defined as the number of rows preceding and including x that are distinct. percent_rank percent_rank () Computes the percent rank of the row within the window partition, where the percent rank of row x is defined by (xy - 1) / (ab - 1) where xy is the rank of x and ab is the number of rows in the window partition. row_number row_number () Computes the sequential row number of the row within its window partition starting with 1 for the first row. ntile ntile ( numeric_expression ) Divides an ordered dataset into a number of buckets as indicated by "numeric_expression" and assigns the appropriate bucket number to each row.