github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/func_string_char_length.test (about) 1 #SELECT,多种语言 2 SELECT CHAR_LENGTH("你好"); 3 SELECT CHAR_LENGTH("français"); 4 SELECT CHAR_LENGTH("にほんご"); 5 SELECT CHAR_LENGTH("Español"); 6 7 #NULL 8 SELECT CHAR_LENGTH(NULL); 9 10 11 create table t1 (a char(20)); 12 insert into t1 values ('123456'),('андрей'); 13 select char_length(a), length(a), a from t1 order by a; 14 drop table t1; 15 16 #EXTRME VALUE 17 select char_length('\n\t\r\b\0\_\%\\'); 18 19 #嵌套 20 21 SELECT CHAR_LENGTH(concat_ws(" ",121,83,81,'76')) as my_column; 22 23 24 25 create table t (c varchar(20)); 26 insert into t values ('\\'); 27 select char_length(c) from t; 28 insert into t values ('0C'); 29 select sum(char_length(c)) from t; 30 insert into t values ('"'); 31 select sum(char_length(c)) from t; 32 insert into t values ('\a'); 33 select sum(char_length(c)) from t; 34 insert into t values ('\b'); 35 select sum(char_length(c)) from t; 36 insert into t values ('\t'); 37 select sum(char_length(c)) from t; 38 insert into t values ('\n'); 39 select sum(char_length(c)) from t; 40 insert into t values ('\r'); 41 select sum(char_length(c)) from t; 42 insert into t values ('10'); 43 select sum(char_length(c)) from t; 44 drop table t; 45 46 47 48 #DATATYPE 49 create table t1(a tinyint, b SMALLINT, c BIGINT, d INT, e BIGINT, f FLOAT, g DOUBLE, h decimal(38,19), i DATE, k datetime, l TIMESTAMP, m char(255), n varchar(255)); 50 insert into t1 values(1, 1, 2, 43, 5, 35.5, 31.133, 14.314, "2012-03-10", "2012-03-12 10:03:12", "2022-03-12 13:03:12", "ab23c", "d5cf"); 51 insert into t1 values(71, 1, 2, 34, 5, 5.5, 341.13, 15.314, "2012-03-22", "2013-03-12 10:03:12", "2032-03-12 13:04:12", "abr23c", "3dcf"); 52 insert into t1 values(1, 1, 21, 4, 54, 53.5, 431.13, 14.394, "2011-03-12", "2015-03-12 10:03:12", "2002-03-12 13:03:12", "afbc", "dct5f"); 53 insert into t1 values(1, 71, 2, 34, 5, 5.5, 31.313, 124.314, "2012-01-12", "2019-03-12 10:03:12", "2013-03-12 13:03:12", "3abd1c", "dcvf"); 54 select char_length(a),char_length(b),char_length(c),char_length(d),char_length(e),char_length(f),char_length(g),char_length(h),char_length(i),char_length(k),char_length(l),char_length(m),char_length(n) from t1; 55 drop table t1; 56 57 #0.5暂不支持time类型 58 #create table t1(a time) 59 #insert into t1 values("10:03:12"); 60 #select char_length(a) from t1; 61 #drop table t1; 62 63 64 #insert into, distinct 65 create table t1(a int, b varchar(255)); 66 insert into t1 select char_length("你好"), "你好"; 67 insert into t1 select char_length("再见"), "再见"; 68 select distinct a, char_length(b) from t1; 69 drop table t1; 70 71 #WHERE 72 drop table if exists t1; 73 create table t1(a INT, b varchar(255)); 74 insert into t1 select char_length("你好"), "你好"; 75 insert into t1 select char_length("再见"), "再见"; 76 select * from t1 where char_length(b)=2; 77 drop table t1; 78 79 80 #ON CONDITION 81 drop table if exists t1; 82 drop table if exists t2; 83 create table t1(a INT, b varchar(255)); 84 create table t2(a INT, b varchar(255)); 85 insert into t1 select char_length("你好"), "你好"; 86 insert into t1 select char_length("再见"), "再见"; 87 insert into t2 select char_length("今天"), "日期时间"; 88 insert into t2 select char_length("明天"), "明天"; 89 SELECT t1.a, t2.a FROM t1 JOIN t2 ON (char_length(t1.b) = char_length(t2.b)); 90 drop table t1; 91 drop table t2; 92 93 #HAVING,比较操作 94 drop table if exists t1; 95 create table t1(a INT, b varchar(255)); 96 insert into t1 select char_length("你好"), "你好"; 97 insert into t1 select char_length("再见"), "再见"; 98 select b from t1 group by b having char_length(b)<3; 99 drop table t1; 100 101 102 #算术操作 103 SELECT char_length("你好")+char_length("再见"); 104