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. max-length can be a maximum of 32767 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.
How CHAR columns are described depends on the client interface, the character sets used, and if character-length semantics are used. For example, in embedded SQL the described length is the maximum number of bytes in the client character set. If the described length would be more than 32767 bytes, the column is described as type DT_LONGVARCHAR. The following table shows some embedded SQL examples and the results returned when a DESCRIBE is performed:
Type being described | Database character set | Client character set | Result of DESCRIBE |
---|---|---|---|
CHAR(10) | Windows-1252 | Windows-1252 | DT_FIXCHAR length 10 |
CHAR(10) | UTF-8 | UTF-8 | DT_FIXCHAR length 10 |
CHAR(10) | Windows-1252 | UTF-8 | DT_FIXCHAR length 30 |
CHAR(20000) | Windows-31J | UTF-8 | DT_LONGVARCHAR |
CHAR(10 CHAR ) | Windows-1252 | Windows-1252 | DT_FIXCHAR length 10 |
CHAR(10 CHAR ) | UTF-8 | UTF-8 | DT_FIXCHAR length 40 |
For ODBC, CHAR is described as either SQL_CHAR or SQL_VARCHAR depending on the odbc_distinguish_char_and_varchar option. See odbc_distinguish_char_and_varchar option.
SQL/2008 Compatible with SQL/2008. In the standard, character-length semantics are the default, whereas in SQL Anywhere byte-length semantics are the default. There are minor inconsistencies with the SQL standard due to case-insensitive collation support and SQL Anywhere's support of blank-padding.
The SQL/2008 standard supports explicit character- or byte-length semantics as SQL language feature T061.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |