BIGINT scalar function

The BIGINT function returns a big integer (a binary integer with a precision of 63 bits) representation of a value of a different data type.

Numeric to BIGINT

Read syntax diagramSkip visual syntax diagramBIGINT(numeric-expression)

String to BIGINT

Read syntax diagramSkip visual syntax diagramBIGINT(string-expression)

Datetime to BIGINT

Read syntax diagramSkip visual syntax diagramBIGINT(datetime-expression)

Boolean to BIGINT

Read syntax diagramSkip visual syntax diagram BIGINT ( boolean-expression )

The schema is SYSIBM.

Numeric to BIGINT
numeric-expression
An expression that returns a value of any built-in numeric data type.

The result is the same number that would occur if the argument were assigned to a big integer column or variable. The fractional part of the argument is truncated. If the whole part of the argument is not within the range of big integers, an error is returned (SQLSTATE 22003).

String to BIGINT
string-expression
An expression that returns a value that is a character-string or Unicode graphic-string representation of a number with a length not greater than the maximum length of a character constant.

The result is the same number that would result from CAST(string-expresssion AS BIGINT). Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming an integer, decimal, floating-point, or decimal floating-point constant (SQLSTATE 22018). If the whole part of the argument is not within the range of big integers, an error is returned (SQLSTATE 22003). The data type of string-expresssion must not be CLOB or DBCLOB (SQLSTATE 42884).

Datetime to BIGINT
datetime-expression
An expression that is of one of the following data types:
  • DATE. The result is a BIGINT value representing the date as yyyymmdd.
  • TIME. The result is a BIGINT value representing the time as hhmmss.
  • TIMESTAMP. The result is a BIGINT value representing the timestamp as yyyymmddhhmmss. The fractional seconds portion of the timestamp value is not included in the result.
Boolean to BIGINT
boolean-expression
An expression that returns a Boolean value (TRUE or FALSE). The result is either 1 (for TRUE) or 0 (for FALSE).

Result

The result of the function is a big integer. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Notes

  • Increasing portability of applications: If the first argument is numeric, or if the first argument is a string and the length argument is specified, use the CAST specification instead of this function to increase the portability of your applications.

Examples

  • Example 1: From ORDERS_HISTORY table, count the number of orders and return the result as a big integer value.
       SELECT BIGINT (COUNT_BIG(*))
         FROM ORDERS_HISTORY
  • Example 2: Using the EMPLOYEE table, select the EMPNO column in big integer form for further processing in the application.
       SELECT BIGINT (EMPNO) FROM EMPLOYEE
  • Example 3: Assume that the column RECEIVED (whose data type is TIMESTAMP) has an internal value equivalent to '1988-12-22-14.07.21.136421'.
       BIGINT(RECEIVED)
    results in the value 19 881 222 140 721.
  • Example 4: Assume that the column STARTTIME (whose data type is TIME) has an internal value equivalent to '12:03:04'.
       BIGINT(STARTTIME)
    results in the value 120 304.
  • Example 5: The following statement returns the value 1 of data type BIGINT.
       values BIGINT(TRUE)
  • Example 6: The following statement returns the value 0 of data type BIGINT.
       values BIGINT(3>3)