DB2 Scalar functions - VARCHAR
The VARCHAR function returns a varying-length character 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 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 actual length of the result is the smallest number of characters that can be used to represent the value of the argument. Leading zeros are not included. If the argument is negative, the first character of the result is a minus sign. Otherwise, the first character is a digit.
The code page of the result is the code page of the section.
The result is a varying-length character string representation of decimal-expression in the form of an SQL decimal constant. The length attribute of the result is 2+p, where p is the precision of decimal-expression. The actual length of the result is the smallest number of characters that can be used to represent the result, except that trailing zeros are included. Leading zeros are not included. If decimal-expression is negative, the first character of the result is a minus sign; otherwise, the first character is a digit or the decimal character. If the scale of decimal-expression is zero, the decimal character is not returned.
The result is a varying-length character 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 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 character of the result is a minus sign; otherwise, the first character is a digit. If floating-point-expression is zero, the result is 0E0.
The result is a varying-length character 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 characters that can represent the value of decimal-floating-point-expression. If decimal-floating-point-expression is negative, the first character of the result is a minus sign; otherwise, the first 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 INFINITY, SNAN, and NAN, respectively, are returned. If the special value is negative, the first 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.
INFINITY
SNAN
NAN
If the second argument is not specified:
The result is a varying-length character string. The length attribute of the result is determined by the value of integer. If character-expression is the FOR BIT DATA subtype, the result is FOR BIT DATA.
If the length of character-expression is greater than the length attribute of the result, several scenarios exist:
The result is a varying-length character string that is converted from graphic-expression. The length attribute of the result is determined by the value of integer.
If the length of graphic-expression that is converted to a character string is greater than the length attribute of the result, several scenarios exist:
The result is a FOR BIT DATA character string.
The VARCHAR function returns a varying-length character string representation of:
In a non-Unicode database, the string units of the result is OCTETS. Otherwise, the string units of the result is determined by the data type of the first argument.
In a Unicode database, when the output string is truncated part-way through a multiple-byte character:
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 VARCHAR(EMPNO,10) INTO :VARHV FROM EMPLOYEE
SELECT VARCHAR(JOB) INTO :JOB_DESC FROM EMPLOYEE WHERE LASTNAME = 'QUINTANA'
SELECT VARCHAR(EDLEVEL) FROM EMPLOYEE WHERE LASTNAME = 'HAAS'
SELECT VARCHAR(SALARY + COMM, ',') FROM EMPLOYEE WHERE LASTNAME = 'HAAS'
values VARCHAR(3=3)
values VARCHAR(3>3)