Oracle 5.0 Reference Manual page 869

Table of Contents

Advertisement

Value
CHAR(4)
'abcdefgh'
'abcd'
The values shown as stored in the last row of the table apply only when not using strict mode; if
MySQL is running in strict mode, values that exceed the column length are not stored, and an error
results.
If a given value is stored into the
columns are not always the same because trailing spaces are removed from
retrieval. The following example illustrates this difference:
mysql>
CREATE TABLE vc (v VARCHAR(4), c CHAR(4));
Query OK, 0 rows affected (0.01 sec)
mysql>
INSERT INTO vc VALUES ('ab
Query OK, 1 row affected (0.00 sec)
mysql>
SELECT CONCAT('(', v, ')'), CONCAT('(', c, ')') FROM vc;
+---------------------+---------------------+
| CONCAT('(', v, ')') | CONCAT('(', c, ')') |
+---------------------+---------------------+
| (ab
)
+---------------------+---------------------+
1 row in set (0.06 sec)
Values in
and
CHAR
VARCHAR
collation assigned to the column.
All MySQL collations are of type PADSPACE. This means that all CHAR, VARCHAR, and
in MySQL are compared without regard to any trailing spaces. "Comparison" in this context does
not include the
[896]
LIKE
example:
mysql>
CREATE TABLE names (myname CHAR(10));
Query OK, 0 rows affected (0.03 sec)
mysql>
INSERT INTO names VALUES ('Monty');
Query OK, 1 row affected (0.00 sec)
mysql>
SELECT myname = 'Monty', myname = 'Monty
+------------------+--------------------+
| myname = 'Monty' | myname = 'Monty
+------------------+--------------------+
|
1 |
+------------------+--------------------+
1 row in set (0.00 sec)
mysql>
SELECT myname LIKE 'Monty', myname LIKE 'Monty
+---------------------+-----------------------+
| myname LIKE 'Monty' | myname LIKE 'Monty
+---------------------+-----------------------+
|
1 |
+---------------------+-----------------------+
1 row in set (0.00 sec)
This is true for all MySQL versions, and it makes no difference whether your version trims trailing
spaces from
VARCHAR
in this regard.
Note
For more information about MySQL character sets and collations, see
Section 10.1, "Character Set
For those cases where trailing pad characters are stripped or comparisons ignore them, if a column
has an index that requires unique values, inserting into the column values that differ only in number
String Types
Storage Required
4 bytes
and
CHAR(4)
', 'ab
| (ab)
columns are sorted and compared according to the character set
pattern-matching operator, for which trailing spaces are significant. For
' |
1 |
values before storing them. Nor does the server SQL mode make any difference
849
VARCHAR(4)
'abcd'
columns, the values retrieved from the
VARCHAR(4)
');
|
' FROM names;
' FROM names;
' |
0 |
Support".
Storage Required
5 bytes
columns upon
CHAR
values
TEXT

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents