octets
For character strings, SQL allows to declare whether the length means characters or octets, i.e. bytes.
CREATE TABLE … (
c1 VARCHAR(10),
c2 VARCHAR(10 CHARACTERS),
c3 VARCHAR(10 OCTETS)
)
In absence of an explicit length unit, characters
is default.✓✗0 The following chart shows that not all systems apply that default correctly. Note that the behavior might also depend on installation defaults, like the character encoding, so that your system might behave differently.
Characters
for national types, depends on nls_string_units
for the other typesnls_length_semantics
for the other typesThe standard defines the keywords characters
and octets
(both plural) for the length units. Yet some systems support different words only.
The <character length unit>
was introduced with ISO/IEC 9075-2:2003 as part of the optional feature T061, “UCS support”. With the 2023 edition of the standard, it has got its own Feature ID: T062, “Character length units”.
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-sql.com on your radar.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »
ISO/IEC 9075-2:2023 §6.1 SR 9