Previous Topic: Bit-Level FunctionsNext Topic: XML Functions


Byte-Level Function

Following is the syntax diagram for byte-level scalar functions:

►►─ INTEXTRACT(expression, expression) ───────────────────────────────────────►◄
INTEXTRACT(expression, expression)

This byte-level function is used to extract the binary value of a single byte of a data value. The function returns an INTEGER result, hence the name INTEXTRACT (integer extract). The first parameter, meaning the first expression in INTEXTRACT(expression, expression), supplies the data value, and the second parameter (the second expression) specifies which byte is wanted.

For example, if variable web_addrs in a C-language program contains the value (in C-style notation) 0x11223344, then INTEXTRACT(web_addrs, 2) returns the value 0x22 in C-style notation or 34 in decimal-style notation, extracted from the second byte from the high-order (left-hand) side of the value, returning an INTEGER result.

The first expression

Representing the first parameter must resolve to INTEGER, SMALLINT, CHAR (non-mixed data only, that is to say, mixed DBCS/SBCS only), or VARCHAR (non-mixed data only). The length of the first parameter is limited only to the SQL-imposed limits for each data type. Though not required, we recommend use of the FOR BIT DATA specification in the CREATE TABLE statement for columns that are going to use byte-level functions.

The second expression

Representing the second parameter must resolve to INTEGER or SMALLINT data.

Following is an example of using INTEXTRACT to get a single node of a web address:

 SELECT INTEXTRACT(web_addrs, 2) FROM web_addresses
Given input of

A web_addrs of 0x11223344 in C-style notation.

Resulting output is

An integer containing 0x00000022 in C-style notation or 34 in decimal-style notation.