DB2 Scalar functions - VARGRAPHIC
The VARGRAPHIC function returns a varying-length graphic string representation of a value of a different data type.
The schema is SYSIBM. The function name cannot be specified as a qualified name when keywords are used in the function signature.
The result is the varying-length graphic string representation of integer-expression in the form of an SQL integer constant. The length attribute of the result depends on whether integer-expression is a small, large or big integer as follows:
The code page of the result is the DBCS code page of the section.
The result is a varying-length graphic string representation of floating-point-expression in the form of an SQL floating-point constant.
The maximum length of the result is 24. The actual length of the result is the smallest number of double-byte characters that can represent the value of floating-point-expression such that the mantissa consists of a single digit other than zero followed by the decimal-character and a sequence of digits. If floating-point-expression is negative, the first double-byte character of the result is a minus sign; otherwise, the first double-byte character is a digit. If floating-point-expression is zero, the result is 0E0.
The result is a varying-length graphic string representation of decimal-floating-point-expression in the form of an SQL decimal floating-point constant. The maximum length of the result is 42. The actual length of the result is the smallest number of double-byte characters that can represent the value of decimal-floating-point-expression. If decimal-floating-point-expression is negative, the first double-byte character of the result is a minus sign; otherwise, the first double-byte character is a digit. If decimal-floating-point-expression is zero, the result is 0.
If the value of decimal-floating-point-expression is the special value Infinity, sNaN, or NaN, the strings G'INFINITY', G'SNAN', and G'NAN', respectively, are returned. If the special value is negative, the first double-byte character of the result is a minus sign. The decimal floating-point special value sNaN does not result in a warning when converted to a string.
If the second argument is not specified:
The result is a varying-length graphic string that is converted from character-expression. The length attribute of the result is determined by the value of integer.
If the length of character-expression that is converted to a graphic string is greater than the length attribute of the result, several scenarios exist:
This function converts character-expression from UTF-8 to UTF-16. Every character of character-expression is converted.
The result is a varying-length graphic string that is converted from character-expression. The length attribute of the result is the minimum of the length attribute of character-expression and the maximum length for the VARGRAPHIC data type.
If the length of character-expression that is converted to a graphic string is greater than the length attribute of the result, an error is returned (SQLSTATE 22001).
For databases with a code set that is not Japanese EUC (code page 954) or Traditional Chinese (code page 964), each single-byte character in character-expression is converted to its equivalent double-byte representation or to the double-byte substitution character in the result. Each double-byte character in character-expression is mapped without extra conversion. If the first byte of a double-byte character appears as the last byte of character-expression, it is converted to the double-byte substitution character. The sequential order of the characters in character-expression is preserved. No warning or error code is generated if one or more double-byte substitution characters are returned in the result.
For details about the conversion process for databases with a code set that is Japanese EUC (code page 954) or Traditional Chinese (code page 964), refer to the Related Links section.
The result is a varying-length graphic string. The length attribute of the result is determined by the value of integer.
If the length of graphic-expression is greater than the length attribute of the result, several scenarios exist:
The VARGRAPHIC function returns a varying-length graphic string representation of:
In a non-Unicode database, the string units of the result is double bytes. Otherwise, the string units of the result is determined by the data type of the first argument.
If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.
SELECT VARGRAPHIC(EDLEVEL) FROM EMPLOYEE WHERE LASTNAME = 'HAAS'
SELECT VARGRAPHIC(SALARY + COMM, ',') FROM EMPLOYEE WHERE LASTNAME = 'HAAS'
values VARGRAPHIC(3=3)
values VARGRAPHIC(3>3)