Ispirer Home Page Ispirer SQLWays Product Page - Migration to MySQL Request SQLWays

MySQL Data Types - CHAR

Versions: MySQL 5.x, 4.x and 3.23

Syntax CHAR[(n)] [CHARACTER SET charset | BINARY | ASCII | UNICODE | BYTE] [COLLATE collate]
Data Fixed-length character data, single-byte and multibyte character sets
Parameters n is the maximum number of characters, optional. CHARACTER SET specifies the character set, COLLATE specifies a collation for the character set.

ASCII is equal to CHARACTER SET latin1, UNICODE is equal to CHARACTER SET ucs2, BINARY is equal to specifying the binary collation;
CHAR BYTE is a synonym for the BINARY data type
Range 0 ⇐ n ⇐ 255
Default n is 1
Padding Right-padded with spaces to n
Trailing Spaces Removed when the value is retrieved if PAD_CHAR_TO_FULL_LENGTH SQL mode is not specified. Trailing spaces are insignificant in comparisons, primary and unique keys
Empty String CHAR(0) is allowed that can store 2 values: '' (empty string) and NULL
Error Handling Exceeding data truncated and a warning is generated if strict SQL mode is not enabled, otherwise in case of non-space characters truncation, an error is raised
Storage Size n bytes
Internals If CHARACTER SET binary is specified, it is automatically converted to the BINARY data type without warning
Version Differences MySQL 4.1 and later - CHARACTER SET and COLLATE options are available.
MySQL 3.23 and earlier - 1 ⇐ n ⇐ 255
Standards ANSI SQL

MySQL CHAR - Equivalents in Other Databases

Database Data Type and Conversion
Oracle CHAR(n), 1 ⇐ n ⇐ 2000/charsize
SQL Server CHAR(n), 1 ⇐ n ⇐ 8000
IBM DB2 CHAR(n), 1 ⇐ n ⇐ 254
PostgreSQL CHAR(n), 1 ⇐ n ⇐ 1G
Sybase ASE CHAR(n), 1 ⇐ n ⇐ pagesize (2K, 4K, 8K or 16K)
Sybase ASA CHAR(n), 1 ⇐ n ⇐ 32767/charsize
Informix CHAR(n), 1 ⇐ n ⇐ 32767
Teradata CHAR(n), 1 ⇐ n ⇐ 64000/charsize
HP Neoview CHAR(n), 1 ⇐ n ⇐ (32708 - size of other columns)
Interbase/Firebird CHAR(n), 1 ⇐ n ⇐ 32767/charsize
Ingres CHAR(n), 1 ⇐ n ⇐ 3200

Related Data Types in MySQL

Data Types
Fixed-length character data NCHAR(n)
Variable-length character data VARCHAR(n) NVARCHAR(n) TINYTEXT TEXT MEDIUMTEXT
Character large objects LONGTEXT

All Data Types

Ispirer Home Page Ispirer SQLWays Product Page - Migration to MySQL Request SQLWays

© 1999-2023, Ispirer Systems, LLC. All Rights Reserved.