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)