The VARCHAR data type stores character data, up to 32767 bytes.
VARCHAR [ ( 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 of 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 VARCHAR, but the declared length refers to bytes, not characters.
VARCHAR can also be specified as CHAR VARYING or CHARACTER VARYING. Regardless of which syntax is used, the data type is described as VARCHAR.
How VARCHAR 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 |
---|---|---|---|
VARCHAR(10) | Windows-1252 | Windows-1252 | DT_VARCHAR length 10 |
VARCHAR(10) | UTF-8 | UTF-8 | DT_VARCHAR length 10 |
VARCHAR(10) | Windows-1252 | UTF-8 | DT_VARCHAR length 30 |
VARCHAR(20000) | Windows-31J | UTF-8 | DT_LONGVARCHAR |
VARCHAR(10 CHAR ) | Windows-1252 | Windows-1252 | DT_VARCHAR length 10 |
VARCHAR(10 CHAR ) | UTF-8 | UTF-8 | DT_VARCHAR length 40 |
For ODBC, VARCHAR is described as SQL_VARCHAR.
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 blank-padding support.
The SQL/2008 standard supports explicit character- or byte-length semantics as SQL language feature T061.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |