DB2 Scalar functions - SUBSTR
The SUBSTR function returns a substring of a string.
The schema is SYSIBM.
If length is explicitly specified, string is effectively padded on the right with the necessary number of blank characters (single-byte for character strings; double-byte for graphic strings) or hexadecimal zero characters (for binary strings) so that the specified substring exists. The default length is the number of string units from the string unit specified by start to the last string unit of string. However, if string is a varying-length string with a length less than start, the default is zero and the result is the empty string. It must be specified as number of string units in the context of the database code page and not the application code page. (For example, the column NAME with a data type of VARCHAR(18) and a value of 'MCKNIGHT' will yield an empty string with SUBSTR(NAME,10)).
If string is:
If string is a character string, the result is a character string represented in the code page and string units of its first argument. If it is a binary string, the result is a binary string. If it is a graphic string, the result is a graphic string represented in the code page and string units of its first argument. If the first argument is a host variable that is not a binary string and not a FOR BIT DATA character string, the code page of the result is the database code page. If any argument of the SUBSTR function can be null, the result can be null; if any argument is null, the result is the null value.
Table 1 shows that the result type and length of the SUBSTR function depend on the type and attributes of its inputs.
The LONG VARCHAR and LONG VARGRAPHIC data types continue to be supported but are deprecated and not recommended.
SUBSTR(:NAME,1,4)
SUBSTR(:NAME,6)
SUBSTR(:NAME,6,2)
SELECT * FROM PROJECT WHERE SUBSTR(PROJNAME,1,10) = 'OPERATION '