1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
CREATE TABLE t1 (a int auto_increment primary key, v varchar(255));
INSERT INTO t1 (v) VALUES
(NULL),
(''),
(0),
('abc'),
('你好'),
('☃');
#
# Verify LENGTH, OCTET_LENGTH
#
SELECT LENGTH(NULL), OCTET_LENGTH(NULL);
SELECT LENGTH(''), OCTET_LENGTH('');
SELECT LENGTH('0'), OCTET_LENGTH('0');
SELECT LENGTH('abc'), OCTET_LENGTH('abc');
SELECT LENGTH('你好'), OCTET_LENGTH('你好');
SELECT LENGTH('☃'), OCTET_LENGTH('☃');
SELECT a, v, LENGTH(v), OCTET_LENGTH(v) FROM t1;
#
# Verify CHAR_LENGTH, CHARACTER_LENGTH
#
SELECT CHAR_LENGTH(NULL), CHARACTER_LENGTH(NULL);
SELECT CHAR_LENGTH(''), CHARACTER_LENGTH('');
SELECT CHAR_LENGTH('0'), CHARACTER_LENGTH('0');
SELECT CHAR_LENGTH('abc'), CHARACTER_LENGTH('abc');
SELECT CHAR_LENGTH('你好'), CHARACTER_LENGTH('你好');
SELECT CHAR_LENGTH('☃'), CHARACTER_LENGTH('☃');
SELECT A, V, CHAR_LENGTH(V), CHARACTER_LENGTH(v) from t1;
DROP TABLE IF EXISTS t1;
|