DB2
DB2 Common DB2 add_months ( date_expression|datetime_expression , integer_expression ) Returns the date resulting from adding integer_expression months to date_expression or datetime_expression. Date_expression and datetime_expression can be a date or datetime value or a string representation of a date or a datetime. add_months ( current_date , 3 ) Result: Returns the date that is three months later than the current date. ascii ( string_expression ) Returns the ASCII code value of the leftmost character of the argument as an integer. ascii ( a ) Result: Returns 65, the ASCII code value of "a". chr ( integer_expression ) Returns the character that has the ASCII code value specified by "integer_expression". "Integer_expression" should be between 0 and 255. chr ( 65 ) Result: Returns a, the character for the ASCII code value of 65. char ( expression )   Alternate syntax: char ( string_expression  , integer_expression ) Returns a fixed-length string representation of "string_expression" with a length of "integer_expression".   Alternate syntax 2: char ( decimal_expression  , character_expression ) Returns a string representation of "decimal_expression" using the decimal separator "character_expression". Returns a string representation of a date/time value or a decimal number. ceiling ( numeric_expression ) Returns the smallest integer greater than or equal to "numeric_expression". ceiling ( 0.75 ) Result: Returns 0.8. coalesce coalesce ( expression_list ) Returns the first non-null argument (or null if all arguments are null). The Coalesce function takes two or more arguments. coalesce ( [Unit price], [Unit sale price] ) Result: Returns the unit price, or the unit sale price if the unit price is null. concat ( string_expression1, string_expression2 ) Returns a string that is the result of concatenating "string_expression1" with "string_expression2". concat ( [Sales target (query)].[Sales staff].[First name], [Sales target (query)].[Sales staff].[Last name] ) Result: Returns the first name and family name; e.g., Bob Smith. date ( expression ) Returns a date from a single input value. "Expression" can be a string or integer representation of a date. date ( '1998-01-08' ) Result: Returns 8 January 1998. day ( date_expression ) Returns the day of the month (1-31) from "date_expression". "Date_expression" can be a date value or a string representation of a date. day ( '1998-01-08' ) Result: Returns 8. dayname ( date_expression ) Returns a character string containing the data source-specific name of the day (for example, Sunday through Saturday or Sun. through Sat. for a data source that uses English, or Sonntag through Samstag for a data source that uses German) for the day portion of "date_expression". "Date_expression" can be a date value or a string representation of a date. dayname ( '1998-01-08' ) Result: Returns Thursday. dayofweek ( date_expression ) Returns the day of the week in "date_expression" as an integer in the range 1 to 7, where 1 represents Sunday. "date_expression" can be a date value or a string representation of a date. dayofweek ( '1998-01-08' ) Result: Returns 5. dayofweek_iso ( date_expression ) Returns the day of the week in "date_expression" as an integer in the range 1 to 7, where 1 represents Monday. "date_expression" can be a date value or a string representation of a date. dayofweek_iso ( '1998-01-08' ) Result: Returns 4. dayofyear ( date_expression ) Returns the day of the year in "date_expression" as an integer in the range 1 to 366. "Date_expression" can be a date value or a string representation of a date. dayofyear ( current_date ) Result: Returns the day of the year for the current date; e.g., if it was January 28, the expression would return 28. days ( expression ) Returns an integer representation of a date. "Expression" can be a date value or a string representation of a date. dec ( string-expression [ , precision-integer [ , scale-integer [ , decimal-character ] ] ] ) Returns the decimal representation of "string-expression" using "precision-integer" and "scale-integer". The "decimal-character" can be used to specify the single-byte character constant used to delimit the decimal digits in "string-expression". The "string-expression" must be formatted as an SQL Integer or Decimal constant.   Alternate syntax: dec ( numeric-expression [ , precision-integer [ , scale-integer ] ] ) Returns the decimal representation of "numeric-expression" using "precision-integer" and "scale-integer".   Alternate syntax 2: dec ( datetime-expression [ , precision-integer [ , scale-integer ] ] ) Returns the decimal representation of "datetime-expression" using "precision-integer" and "scale-integer". decimal ( string-expression [ , precision-integer [ , scale-integer [ , decimal-character ] ] ] ) Returns the decimal representation of "string-expression" using "precision-integer" and "scale-integer". The "decimal-character" can be used to specify the single-byte character constant used to delimit the decimal digits in "string-expression". The "string-expression" must be formatted as an SQL Integer or Decimal constant.   Alternate syntax: decimal ( numeric-expression [ , precision-integer [ , scale-integer ] ] ) Returns the decimal representation of "numeric-expression" using "precision-integer" and "scale-integer".   Alternate syntax 2: decimal ( datetime-expression [ , precision-integer [ , scale-integer ] ] ) Returns the decimal representation of "datetime-expression" using "precision-integer" and "scale-integer". difference ( string_expression1 , string_expression2 ) Returns an integer value representing the difference between the values returned by the data source-specific soundex function for "string_expression1" and "string_expression2". The value returned ranges from 0 to 4, with 4 indicating the best match. Note that 4 does not mean that the strings are equal. Example: difference ([Sales target (query)].[Sales staff].[First name],[Sales (query)].[Retailers].[Contact first name]) Result: 0 Example: difference ([Sales target (query)].[Sales staff].[First name],[Sales target (query)].[Sales staff].[First name]) Result: 4 digits ( numeric_expression ) Returns the character string representation of a non-floating point number. double ( expression ) Returns the floating-point representation of an expression. "Expression" can either be a numeric or string expression. event_mon_state ( string_expression ) Returns the operational state of a particular state monitor. float ( numeric_expression ) Returns the floating-point representation of a number. hex ( expression ) Returns the hexadecimal representation of a value. hour ( time_expression ) Returns the hour, an integer from 0 (midnight) to 23 (11:00 pm), from "time_expression". "Time_expression" can be a time value or a string representation of a time. hour ( 01:22:45 ) Result: Returns 1. insert ( string_expression1, integer_expression1, integer_expression2, string_expression2 ) Returns a string where "integer_expression2" characters have been deleted from "string_expression1" beginning at "integer_expression1" and where "string_expression2" has been inserted into "string_expression1" at its start. The first character in the string is at position 1. integer ( expression ) Returns the integer representation of an expression. "Expression" can be a numeric value or a string representation of a number. Example: integer ( 84.95 ) Result: 84 int ( expression ) Returns the integer representation of an expression. "Expression" can be a numeric value or a string representation of a number. Example: int ( 84.95 ) Result: 84 julian_day ( expression ) Returns an integer value representing the number of days from January 1, 4712 BC (the start of the Julian date calendar) to the date value specified in "expression". "Expression" can be a date value or a string representation of a date. julian_day ( '2009-06-29' ) Result: 2455012.22130739595741034 lcase ( string_expression ) Returns "string_expression" with all uppercase characters shifted to lowercase. lcase ( [Sales (query)].[Sales staff].[Last name] ) Result: Returns family names with no uppercase letters. left ( string_expression, integer_expression ) Returns the leftmost "integer_expression" characters of "string_expression". left ( [Sales (query)].[Sales staff].[Last name] , 3 ) Result: Returns the first three characters of each family name. length ( expression ) Returns the length of the operand in bytes. Exception: double byte string types return the length in characters. length ( [Sales (query)].[Sales staff].[Record start date] ) Result: Returns 4; dates always return a value of 4. locate ( string_expression1, string_expression2 [ , integer_expression ] ) Returns the starting position of the first occurrence of "string_expression1" within "string_expression2". The search starts at position start "integer_expression" of "string_expression2". The first character in a string is at position 1. If "string_expression1" is not found, zero is returned. locate ( A, [Sales (query)].[Sales staff].[Last name] , 2 ) Result: Returns the position of the character A in the family names starting at the second character of the family name. long_varchar ( string_expression ) Returns a long string. ltrim ( string_expression ) Returns "string_expression" with leading spaces removed. ltrim ( [Sales (query)].[Sales staff].[Last name] ) Result: Returns family names with any leading spaces removed. microsecond ( expression ) Returns the microsecond (time-unit) part of a value. "Expression" can be a timestamp or a string representation of a timestamp. microsecond ( 01:45:34.056 ) Result: Returns 056. midnight_seconds ( expression ) Returns an integer value in the range 0 to 86400 representing the number of seconds between midnight and time value specified in the argument. "Expression" can be a time value, a timestamp or a string representation of a time. midnight_seconds ( 01:45:34.056 ) Result: Returns 6334. minute ( time_expression ) Returns the minute (an integer from 0-59) from "time_expression". "Time_expression" can be a time value, a timestamp, or a string representation of a time. minute ( 01:45:34.056 ) Result: Returns 45. month ( date_expression ) Returns the month (an integer from 1-12) from "date_expression". month ( 2005-11-01 ) Result: Returns 11. monthname ( date_expression ) Returns a character string containing the data source-specific name of the month (for example, January through December or Jan. through Dec. for an English data source, or Januar through Dezember for a German data source) for the month portion of "date_expression". monthname ( 2005-11-01 ) Result: November quarter ( date_expression ) Returns the quarter in "date_expression" as a number in the range 1 to 4, where 1 represents January 1 through March 31. quarter ( 2005-11-01 ) Result: Returns 4. radians ( numeric_expression ) Returns the number of radians converted from "numeric_expression" degrees. repeat ( string_expression, integer_expression ) Returns a string consisting of "string_expression" repeated "integer_expression" times. repeat ( XYZ, 3 ) Result: Returns XYZXYZXYZ. replace ( string_expression1, string_expression2, string_expression3 ) Replaces all occurrences of "string_expression2" in "string_expression1" with "string_expression3". replace ( [Sales (query)].[Sales staff].[Position code], A, a ) Result: Returns position codes with all occurrences of "A" replaced by "a". right ( string_expression, integer_expression ) Returns the rightmost "integer_expression" characters of "string_expression". right ( [Sales (query)].[Sales staff].[Position code], 3 ) Result: Returns the rightmost 3 characters of each position code. round ( numeric_expression, integer_expression ) Returns "numeric_expression" rounded to "integer_expression" places to the right of the decimal point. If "integer_expression" is negative, "numeric_expression" is rounded to the nearest absolute value "integer_expression" places to the left of the decimal point. Rounding takes place before data formatting is applied. round ( 3.14159265, 3 ) Result: Returns 3.142. rtrim ( string_expression ) Returns "string_expression" with trailing spaces removed. rtrim ( [Sales (query)].[Sales staff].[Last name] ) Result: Returns family names with any spaces at the end of the name removed. second ( time_expression ) Returns the second (an integer from 0-59) from "time_expression". second ( 01:45:34.056 ) Result: Returns 34. sign ( numeric_expression ) Returns an indicator of the sign of "numeric_expression": +1 if "numeric_expression" is positive, 0 if zero, or -1 if negative. sign ( [Revenue] ) Result: Returns + for positive values and - for negative values. smallint ( expression ) Returns the small integer representation of a number. soundex ( string_expression ) Returns a 4 character string code obtained by systematically abbreviating words and names in "string_expression" according to phonetics. Can be used to determine if two strings sound the same. For example, does sound-of ('SMITH') = sound-of ('SMYTH'). space ( integer_expression ) Returns a string consisting of "integer_expression" spaces. space ( 5 ) Result: Returns 5 spaces. substr ( string_expression , integer_expression1 [ , integer_expression2 ] ) Returns the substring of "string_expression" that starts at position "integer_expression1" for "integer_expression2" characters. The first character in "string_expression" is at position 1. substr ( [Sales (query)].[Sales staff].[Position code], 3 , 5 ) Result: Returns characters 3 to 7 of the position codes. table_name ( string_expression1 [ , string_expression2 ] ) Returns an unqualified name of a table or view based on the object name in "string_expression1" and the schema name given in "string_expression2". It is used to resolve aliases. table_schema ( string_expression1 [ , string_expression2 ] ) Returns the schema name portion of the two-part table or view name based on the object name in "string_expression1" and the schema name in "string_expression2". It is used to resolve aliases. time ( expression ) Returns a time from a value. timestamp ( expression1 [ , expression2 ] ) Returns a timestamp from a value or a pair of values. "Expression1" must represent a date value, and "expression2" must represent a time value. timestamp ( 11 November 2005 , 12:00:00.000000 ) Result: Returns 2005-11-11-12:00:00.000000. timestamp_iso ( expression ) Returns a datetime in the ISO format (yyyy-mm-dd hh:mm:ss.nnnnnn) converted from the IBM format (yyyy-mm-dd-hh.mm.ss.nnnnnn). If "expression" is a time, it inserts the value of the CURRENT DATE for the date elements and zero for the fractional time element. timestamp_iso ( 11 November 2005 , 12:00:00.000000 ) Result: Returns 2005-11-11 12:00:00.000000. timestampdiff ( expression1, expression2 ) Returns an estimated number of intervals of type "expression1" based on the difference between two timestamps. "Expression2" is the result of subtracting two timestamp types and converting the result to CHAR. Valid values of "expression1" are: 1 Fractions of a second; 2 Seconds; 4 Minutes; 8 Hours; 16 Days; 32 Weeks; 64 Months; 128 Quarters; 256 Years. to_char ( timestamp_expression , format_string ) Returns the string representation of a timestamp with the format of "format_string". to_char ( numeric_expression , format_string ) Returns the string representation of a numeric value with the format of "format_string". to_char ( character_expression ) Returns the varchar string representation of character_expression. to_date ( expression1 , string_expression2 ) Converts "expression1" to a datetime value as specified by the format "string_expression2". The first argument "expression1" may be of type string or numeric. to_date ( '2013-02-27 15:13:14' , 'YYYY-MM-DD HH24:MI:SS' ) Result: Returns datetime with value '2013-02-27 15:13:14'. translate ( string_expression1 [ , string_expression2, string_expression3 [ , string_expression4 ] ] ) Returns "string_expression1" in which characters from "string_expression3" are translated to the equivalent characters in "string_expression2". "String_expression4" is a single character that is used to pad "string_expression2" if it is shorter than "string_expression3". If only "string_expression1" is present, then this function translates it to uppercase characters. translate ( 'abcdefg' ) Result: Returns ABCDEFG. translate ( 'mnlop' , n, m , - ) Result: Returns n-nlop. trunc ( numeric_expression1 [ , numeric_expression2 ] ) Returns "numeric_expression1" truncated to "numeric_expression2" places to the right of the decimal point. If "numeric_expression2" is negative, "numeric_expression1" is truncated to the absolute value of "numeric_expression2" places to the left of the decimal point. If "numeric_expression2" is not specified, "numeric_expression1" is truncated at the decimal point. Example: trunc ( 3.14159265, 3 ) Result: 3.141. Example: trunc ( 3.14159265 ) Result: 3 trunc ( datetime_expression [, format_string [, locale_name ] ] ) Returns "datetime_expression" rounded to the unit specified by format_string. If format_string is not specified, datetime_expression is rounded to the nearest day as if 'DD' were specified for format_string. locale_name is a string constant specifying the locale used to determine the first day of the week. If locale_name is not specified, the value of CURRENT LOCALE LC_TIME is used. Example: trunc ( TIMESTAMP('2000-07-31 15:05:05.123456'), 'DD' ) Result: 2000-07-31 00:00:00.0 truncate ( numeric_expression1 [ , numeric_expression2 ] ) Returns "numeric_expression1" truncated to "numeric_expression2" places to the right of the decimal point. If "numeric_expression2" is negative, "numeric_expression1" is truncated to the absolute value of "numeric_expression2" places to the left of the decimal point. If "numeric_expression2" is not specified, "numeric_expression1" is truncated at the decimal point. Example: truncate ( 3141.59265, -3 ) Result: 3. Example: truncate ( 3141.59265 ) Result: 3141 truncate ( datetime_expression [, format_string [, locale_name ] ] ) Returns "datetime_expression" rounded to the unit specified by format_string. If format_string is not specified, datetime_expression is rounded to the nearest day as if 'DD' were specified for format_string. locale_name is a string constant specifying the locale used to determine the first day of the week. If locale_name is not specified, the value of CURRENT LOCALE LC_TIME is used. Example: truncate ( TIMESTAMP('2000-07-31 15:05:05.123456'), 'DD' ) Result: 2000-07-31 00:00:00.0 ucase ( string_expression ) Returns "string_expression" with all lowercase characters shifted to uppercase. ucase ( XY896Zbced789 ) Result: Returns XY896ZBCED789. value ( expression_list ) Returns the first non-null argument (or null if all arguments are null). The Value function takes two or more arguments. value ( [Unit cost], [Unit price], [Unit sale price] ) Result: Returns the first non-null value. varchar ( expression [ , numeric_expression ] ) Returns a VARCHAR representation of expression, with length numeric_expression. week ( date_expression ) Returns the week of the year in "date_expression" as an integer value in the range 1 to 53. week ( 11 November 2005 ) Result: Returns 45. year ( date_expression ) Returns the year from "date_expression". year ( 11 November 2005 ) Result: Returns 2005.
DB2 Cast cast_char ( expression [ , numeric_expression ] ) Returns the first "numeric_expression" characters of the value of "expression" cast as a string. The whole string is returned when the second argument is not specified. Example: cast_char ([Inventory (query)].[Inventory].[Quantity shipped]) Result: 53730 cast_date ( expression ) Returns the value of "expression" cast as a date. cast_decimal ( expression [ , numeric_expression1, numeric_expression2 ] ) Returns the value of "expression" cast as a decimal with the precision of "numeric_expression1" and scale of "numeric_expression2". cast_double ( expression ) Returns the value of "expression" cast as a double. cast_double_precision ( expression ) Returns the value of "expression" cast as a double. cast_float ( expression ) Returns the value of "expression" cast as a float. cast_integer ( expression ) Returns the value of "expression" cast as a integer. cast_integer ( 84.95 ) Result: 84 cast_longvarchar ( string_expression ) Returns the value of "string_expression" cast as a longvarchar. cast_smallint ( expression ) Returns the value of "expression" cast as a smallint. cast_time ( string_expression ) Returns the value of "string_expression" cast as a time value. cast_timestamp ( expression ) Returns the value of "expression" cast as a datetime. cast_varchar ( expression, integer_expression ) Returns the value of "expression" cast as a varchar with length "integer_expression".
DB2 Math log ( numeric_expression ) Returns the natural logarithm of "numeric_expression". log10 ( numeric_expression ) Returns the base ten logarithm of "numeric_expression". rand ([ integer_expression ]) Generates a random number. Optional argument "integer_expression" may be used as a seed value.
DB2 Trigonometry acos ( numeric_expression ) Returns the arccosine of "numeric_expression" in radians. The arccosine is the angle whose cosine is "numeric_expression". asin ( numeric_expression ) Returns the arcsine of "numeric_expression" in radians. The arcsine is the angle whose sine is "numeric_expression". atan ( numeric_expression ) Returns the arctangent of "numeric_expression" in radians. The arctangent is the angle whose tangent is "numeric_expression". atan2 ( numeric_expression1 , numeric_expression2 ) Returns the arctangent of the x and y coordinates specified by "numeric_expression1" and "numeric_expression2", respectively, in radians. The arctangent is the angle whose tangent is "numeric_expression2" / "numeric_expression1". atanh ( numeric_expression ) Returns the hyperbolic arctangent of "numeric_expression" where "numeric_expression" is an angle expressed in radians. cos ( numeric_expression ) Returns the cosine of "numeric_expression" where "numeric_expression" is an angle expressed in radians. cosh ( numeric_expression ) Returns the hyperbolic cosine of "numeric_expression" where "numeric_expression" is an angle expressed in radians. cot ( numeric_expression ) Returns the cotangent of "numeric_expression" where "numeric_expression" is an angle expressed in radians. degrees ( numeric_expression ) Returns "numeric_expression" radians converted to degrees. sin ( numeric_expression ) Returns the sine of "numeric_expression" where "numeric_expression" is an angle expressed in radians. sinh ( numeric_expression ) Returns the hyperbolic sine of "numeric_expression" where "numeric_expression" is an angle expressed in radians. tan ( numeric_expression ) Returns the tangent of "numeric_expression" where "numeric_expression" is an angle expressed in radians. tanh ( numeric_expression ) Returns the hyperbolic tangent of "numeric_expression" where "numeric_expression" is an angle expressed in radians.