The CHAR data type stores character data, up to 32767 bytes.
CHAR [ ( max-length [ CHAR | CHARACTER ] ) ]
max-length The maximum length of the string. If byte-length semantics are used (CHAR or CHARACTER is not specified as part of the length), then the length is in bytes, and the length must be in the range 1 to 32767. If the length is not specified, then it is 1.
If character-length semantics are used (CHAR or CHARACTER is specified as part of the length), then the length is in characters, and you must specify max-length. When using character-length semantics, the length multiplied by the maximum length of a character in the database encoding must not exceed 32767 bytes. The following table shows the maximum lengths for the supported types of character sets:
|Character set||Maximum length of CHAR|
|Single-byte character set||32767 characters|
|Double-byte character set||16383 characters|
Multibyte characters can be stored as CHAR, but the declared length refers to bytes, not characters, unless character-length semantics are used.
CHAR can also be specified as CHARACTER. Regardless of which syntax is used, the data type is described as CHAR.
CHAR is semantically equivalent to VARCHAR, although they are different types. In SQL Anywhere, CHAR is a variable-length type. In other relational database management systems, CHAR is a fixed-length type, and data is padded with blanks to max-length bytes of storage. SQL Anywhere does not blank-pad stored character data.
Using character-length semantics may impact what is returned when a client application performs a DESCRIBE on a column, depending on the interface used. For example, when an embedded SQL client performs a DESCRIBE on a column that was declared using byte-length semantics, the length returned is the byte length specified. So, a CHAR(10) column is described as type DT_FIXCHAR with a length of 10 bytes. However, when an embedded SQL client performs a DESCRIBE on a column that was declared using character-length semantics, the length returned is the maximum byte length in the client's CHAR character set. For example, for an embedded SQL client using UTF-8 as the CHAR character set, a CHAR(10 CHAR) column is described as type DT_FIXCHAR with a length of 40 bytes (10 characters multiplied by the maximum of four bytes per character).
SQL/2003 Compatible with SQL/2003. Character-length semantics is a vendor extension.
|Envoyer votre avis sur cette page par email.||Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|