CHAR 和 VARCHAR

字符串数据类型,固定长度或可变长度。

句法:

CHAR [ ( n_chars ) ]
VARCHAR [ ( n_chars ) ]

例子:

SELECT CAST('ABC' AS CHAR(10)) -- 'ABC       ' (padded with spaces on the right)
SELECT CAST('ABC' AS VARCHAR(10)) -- 'ABC' (no padding due to variable character)
SELECT CAST('ABCDEFGHIJKLMNOPQRSTUVWXYZ' AS CHAR(10))  -- 'ABCDEFGHIJ' (truncated to 10 characters)