Column substrings in single-byte code sets
You can use column substrings in single-byte code sets.
Suppose that you want to retrieve the customer_num column
and the seventh through ninth bytes of the lname column from
the customer table. To perform this query, use a column substring
for the lname column in your SELECT statement, as follows:
SELECT customer_num, lname[7,9] as lname_subset
FROM customer WHERE lname = 'Albertson'
If the lname column
value is
Albertson
, the query returns these results.customer_num | lname_subset |
---|---|
114 | son |
Because the locale supports a single-byte code set,
the preceding query seems to return the seventh through ninth characters
of the name Albertson
. Column substrings, however,
are byte based, and the query returns the seventh through ninth bytes
of the name. Because one byte is equal to one character in single-byte
code sets, the distinction between characters and bytes in column
substrings is not apparent in these code sets.