首页 > 应用开发 > IT综合 > Column Length Semantics
Column length semantics determine whether the length of a column is specified in bytes or in characters. You use BYTE to specify that the length is in bytes, and you use CHAR to specify that the length is in characters. CHAR length semantics is also known as codepoint length semantics.
Because some character sets require more than one byte for each character, a specification of 10 BYTE for a column might actually store less than 10 characters for certain character sets, but a 10 CHAR specification ensures that the column can store 10 characters, regardless of the character set. Only Oracle9i Database or later databases can specify CHAR length semantics.
You set the length semantics for an Oracle database using the NLS_LENGTH_SEMANTICS initialization parameter, and all VARCHAR2 and CHAR
columns use the setting specified for this initialization parameter as
the default. If this initialization parameter is not set, then the
default setting is BYTE.
An individual column can override the length semantics for the database. For example, if the length semantics for a site is CHAR, then you can still specify BYTE for the length semantics of an individual column using the CREATE TABLE or ALTER TABLE statement.
The following statement creates a table and specifies the column length in bytes:
CREATE TABLE byte_col (a VARCHAR2(10 BYTE));
The following statement creates a table and specifies the column length in characters:
CREATE TABLE char_col (a VARCHAR2(10 CHAR));
Note:
A database must have a compatibility level of 9.0.1 or higher to haveCHAR length semantics. The compatibility level is controlled by the COMPATIBLE initialization parameter.来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/161195/viewspace-1050458/ ,如需转载,请注明出处,否则将追究法律责任。