CHAR
CHAR is a fixed-length character type with a maximum length of 255. When the character length is less than the specified maximum length, the system does not automatically use spaces to fill to the maximum length. Spaces are not considered during string comparison.
Syntax
Among them` N 'represents the maximum length of the character type' CHAR ', ranging from 1 to 255.
Example
- Create a
CHARtype with a fixed length of 5:
- Insert a string that is not long enough:
The result will return a string with a length of 10, for example: 'abcd'
- Insert a string that exceeds the specified length:
The result will return a string of length 3, for example: 'abc' (only the first 3 characters are taken)
- When comparing char, ignore trailing spaces:
The result will return true because trailing spaces are ignored during comparison.
Notes
- When performing string comparisons, consider the characteristic that trailing spaces in the
CHARtype are ignored. - Depending on actual needs, choose between the
CHARtype and theVARCHARtype appropriately. If the data length is fixed or varies within a small range, using theCHARtype can improve performance; conversely, if the data length varies greatly, it is recommended to use theVARCHARtype to save storage space.
