CREATE TABLE t (c1 char(10), c2 varchar(10));
INSERT INTO t VALUES ('abc', 'abc');
SELECT length(c1), length(c2) FROM t;What does this return?
- a3 and 3 — length() ignores char(n)'s trailing pad spaces✓
- b10 and 3 — char(n) always reports its declared width
- c10 and 10 — both columns report their declared width
- d3 and 10 — varchar(n) reports its declared width, char(n) does not
Explanation:char(n) physically pads the stored value with trailing spaces up to n, but length() (like most string functions) treats trailing pad spaces as insignificant and strips them before counting. So length() returns 3 for both columns even though c1 is internally padded to 10 bytes.