This is an old revision of the document!
The SUBSTRING function returns a new character string that is a portion of another column or string.
The new string begins at the specified starting point in the original column or string and extends the number of characters specified in the length parameter. If the length parameter is omitted, the new string extends to the end of the original string.
The return data type is C STRING.
SUBSTRING( <column_spec | 'string' FROM start_no [ FOR length ]))
Required. This is the optionally database.table qualified column or string literal enclosed in single quotes that contains the characters that will be returned.
Required. The FROM start_no is a number indicating the number of characters where in the column or string to start the extraction of the partial string. The start_no
String | M | y | s | r | i | n | g | ||
---|---|---|---|---|---|---|---|---|---|
Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
If the start_no was 4 in the string above, then 's' would be the first character of the returned substring.
Optional. This indicates the number of characters after and including the start character, that will be returned. If omitted, all of the remaining characters after and including the start character will be returned.
SELECT product_no, SUBSTRING(PRODUCTS.PRODUCT_NO FROM 2 FOR 3) AS Sub1, SUBSTRING(PRODUCTS.PRODUCT_NO FROM 5) AS Sub2 FROM products Product_No Sub1 Sub2 ASUP93541 SUP 93541 BPRI54687 PRI 54687