OceanBase 1.0字符集为utf8mb4,暂不支持其它字符集。utf8mb4字符集对应的collation支持utf8mb4_bin、utf8mb4_general_ci这两种,默认为utf8mb4_general_ci。
CONCAT(str1,…,strN)
把一个或多个字符串连接成一个字符串。左右参数都必须是字符串类型或NULL,否则报错。如果执行成功,则返回连接后的字符串;参数中有一个值是NULL结果就是NULL。
说明:str参数可以是数值类型,系统能隐式转换为字符串处理。
Oceanbase>select concat('test'), concat('test','OceanBase'), concat('test', 'OceanBase', '1.0'), concat('test','OceanBase','1.0', NULL)\G;
*************************** 1. row ***************************
concat('test'): test
concat('test','OceanBase'): testOceanBase
concat('test', 'OceanBase', '1.0'): testOceanBase1.0
concat('test','OceanBase','1.0', NULL): NULL
1 row in set (0.00 sec)
SUBSTRINGSUBSTRING(str,pos)
SUBSTRING(str FROM pos)
SUBSTRING(str,pos,len)
SUBSTRING(str FROM pos FOR len)
和SUBSTR同语义。
SUBSTRSUBSTR(str,pos,len)
SUBSTR(str,pos)
SUBSTR(str FROM pos)
SUBSTR (str FROM pos FOR len)
返回一个子字符串,起始于位置pos,长度为len。使用FROM的格式为标准SQL语法。
Oceanbase>SELECT SUBSTR('abcdefg',3), SUBSTR('abcdefg',3,2), SUBSTR('abcdefg',-3), SUBSTR('abcdefg',3,-2), SUBSTR('abcdefg' from -4 for 2)\G;
*************************** 1. row ***************************
SUBSTR('abcdefg',3): cdefg
SUBSTR('abcdefg',3,2): cd
SUBSTR('abcdefg',-3): efg
SUBSTR('abcdefg',3,-2):
SUBSTR('abcdefg' from -4 for 2): de
1 row in set (0.00 sec)
TRIM([[{BOTH | LEADING | TRAILING}] [remstr] FROM] str)
Oceanbase>SELECT TRIM(' bar '),
-> TRIM(LEADING 'x' FROM 'xxxbarxxx'),
-> TRIM(BOTH 'x' FROM 'xxxbarxxx'),
-> TRIM(TRAILING 'x' FROM 'xxxbarxxx')\G;
*************************** 1. row ***************************
TRIM(' bar '): bar
TRIM(LEADING 'x' FROM 'xxxbarxxx'): barxxx
TRIM(BOTH 'x' FROM 'xxxbarxxx'): bar
TRIM(TRAILING 'x' FROM 'xxxbarxxx'): xxxbar
1 row in set (0.01 sec)
Oceanbase>SELECT LENGTH('text');
+----------------+
| LENGTH('text') |
+----------------+
| 4 |
+----------------+
1 row in set (0.00 sec)
Oceanbase>select length(-1.23);
+---------------+
| length(-1.23) |
+---------------+
| 5 |
+---------------+
1 row in set (0.00 sec)
Oceanbase>select length(1233e);
ERROR 1054 (42S22): Unknown column '1233e' in 'field list'
Oceanbase>SELECT UPPER('OceanBase您好!');
+-----------------------------+
| UPPER('OceanBase您好!') |
+-----------------------------+
| OCEANBASE您好! |
+-----------------------------+
1 row in set (0.00 sec)
Oceanbase>select upper(e);
ERROR 1054 (42S22): Unknown column 'e' in 'field list'
Oceanbase>select upper(1.235.);
ERROR 1064 (42000): You have an error in your SQL syntax;
Oceanbase>SELECT LOWER('OceanBase您好!');
+-----------------------------+
| LOWER('OceanBase您好!') |
+-----------------------------+
| oceanbase您好! |
+-----------------------------+
1 row in set (0.00 sec)
Oceanbase>select lower(1.23) ;
+-------------+
| lower(1.23) |
+-------------+
| 1.23 |
+-------------+
1 row in set (0.00 sec)
Oceanbase>select lower(1.23h);
ERROR 1583 (42000): Incorrect parameters in the call to native function 'lower'
Oceanbase>select lower(1.23e);
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'lower'
Oceanbase>SELECT HEX(255);
-> FF
Oceanbase>SELECT HEX('abc');
-> 616263
Oceanbase>SELECT HEX('OceanBase'),
-> HEX(123),
-> HEX(0x0123);
+--------------------+----------+-------------+
| HEX('OceanBase') | HEX(123) | HEX(0x0123) |
+--------------------+----------+-------------+
| 4F6365616E42617365 | 7B | 0123 |
+--------------------+----------+-------------+
1 row in set (0.01 sec)
Oceanbase>select hex(0x012);
+------------+
| hex(0x012) |
+------------+
| 0012 |
+------------+
1 row in set (0.00 sec)
Oceanbase>SELECT HEX('OceanBase'),
-> UNHEX('4f6365616e42617365'),
-> UNHEX(HEX('OceanBase')),
-> UNHEX(NULL)\G;
*************************** 1. row ***************************
HEX('OceanBase'): 4F6365616E42617365
UNHEX('4f6365616e42617365'): OceanBase
UNHEX(HEX('OceanBase')): OceanBase
UNHEX(NULL): NULL
1 row in set (0.00 sec)
Oceanbase>select unhex(abc);
ERROR 1054 (42S22): Unknown column 'abc' in 'field list';
注:INT2IP为OceanBase特有函数。
Oceanbase>SELECT INT2IP(16777216),
-> HEX(16777216),
-> INT2IP(1);
+------------------+---------------+-----------+
| INT2IP(16777216) | HEX(16777216) | INT2IP(1) |
+------------------+---------------+-----------+
| 1.0.0.0 | 1000000 | 0.0.0.1 |
+------------------+---------------+-----------+
1 row in set (0.00 sec)
注:IP2INT为OceanBase特有函数。
Oceanbase>SELECT IP2INT('0.0.0.1'),
-> HEX(IP2INT('0.0.0.1')),
-> HEX(IP2INT('1.0.0.0')),
-> IP2INT('1.0.0.257')\G;
*************************** 1. row ***************************
IP2INT('0.0.0.1'): 1
HEX(IP2INT('0.0.0.1')): 1
HEX(IP2INT('1.0.0.0')): 1000000
IP2INT('1.0.0.257'): NULL
1 row in set (0.01 sec)
Oceanbase>SELECT 'ab%' LIKE 'abc%' ESCAPE 'c';
+------------------------------+
| 'ab%' LIKE 'abc%' ESCAPE 'c' |
+------------------------------+
| 1 |
+------------------------------+
1 row in set (0.00 sec)
Oceanbase>select 'a_c' like 'a\\_c';
+--------------------+
| 'a_c' like 'a\\_c' |
+--------------------+
| 1 |
+--------------------+
1 row in set (0.00 sec)
Oceanbase>select 'abc_' like 'abcdd_' escape 'dd';
ERROR 1064 (42000): Incorrect arguments to ESCAPE
Oceanbase>select 1234 regexp 1;
+---------------+
| 1234 regexp 1 |
+---------------+
| 1 |
+---------------+
1 row in set (0.00 sec)
Oceanbase>select 'hello' rlike 'h%';
+---------------------+
| 'hello' rlike 'h%' |
+---------------------+
| 0 |
+---------------------+
1 row in set (0.00 sec)
Oceanbase>select 1234 regexp ^y;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL server version for the right syntax to use near '^y' at line 1
Oceanbase>select yunzhi regexp '^y';
ERROR 1054 (42S22): Unknown column 'yunzhi' in 'field list'
Oceanbase>select 'hello' not rlike '*h*';
ERROR 1139 (42000): Got error 'empty (sub)expression' from regexp
Oceanbase>select repeat('1',-1), repeat(null,null),repeat('test',4);
+----------------+-------------------+------------------+
| repeat('1',-1) | repeat(null,null) | repeat('test',4) |
+----------------+-------------------+------------------+
| | NULL | testtesttesttest |
+----------------+-------------------+------------------+
1 row in set (0.00 sec)
Oceanbase>select repeat(11111,'2');
+-------------------+
| repeat(11111,'2') |
+-------------------+
| 1111111111 |
+-------------------+
1 row in set (0.00 sec)
Oceanbase>select substring_index('abcdabc', 'abc', 0), substring_index('abcdabc', 'abc', 1), substring_index('abcdabc', 'abc', 2), substring_index('abcdabc', 'abc', 3), substring_index('abcdabc', 'abc', -1), substring_index('abcdabc', 'abc', -2), substring_index('abcdabc', 'abc', -3)\G;
*************************** 1. row ***************************
substring_index('abcdabc', 'abc', 0):
substring_index('abcdabc', 'abc', 1):
substring_index('abcdabc', 'abc', 2): abcd
substring_index('abcdabc', 'abc', 3): abcdabc
substring_index('abcdabc', 'abc', -1):
substring_index('abcdabc', 'abc', -2): dabc
substring_index('abcdabc', 'abc', -3): abcdabc
1 row in set (0.00 sec)
Oceanbase>SELECT LOCATE('bar', 'foobarbar');
-> 4
Oceanbase>SELECT LOCATE('xbar', 'foobar');
-> 0
Oceanbase>SELECT LOCATE('bar', 'foobarbar',5);
-> 7
Oceanbase>SELECT INSTR('foobarbar', 'bar');
-> 4
Oceanbase>SELECT INSTR('xbar', 'foobar');
-> 0
Oceanbase>SELECT REPLACE('abc.efg.gpg.nowdew.abc.dabc.e', 'abc.', 'www');
+---------------------------------------------------------+
| REPLACE('abc.efg.gpg.nowdew.abc.dabc.e', 'abc.', 'www') |
+---------------------------------------------------------+
| wwwefg.gpg.nowdew.wwwdwwwe |
+---------------------------------------------------------+
1 row in set (0.00 sec)
Oceanbase>select field('abc','abc1','abc2','abc','abc4','abc'), field(NULL, 'null1', NULL);
+-----------------------------------------------+----------------------------+
| field('abc','abc1','abc2','abc','abc4','abc') | field(NULL, 'null1', NULL) |
+-----------------------------------------------+----------------------------+
| 3 | 0 |
+-----------------------------------------------+----------------------------+
1 row in set (0.00 sec)
Oceanbase>select elt(3, 'abc1', 'abc2', 'abc', 'abc4', 'abc'), elt(0, 'null1', NULL);
+----------------------------------------------+-----------------------+
| elt(3, 'abc1', 'abc2', 'abc', 'abc4', 'abc') | elt(0, 'null1', NULL) |
+----------------------------------------------+-----------------------+
| abc | NULL |
+----------------------------------------------+-----------------------+
1 row in set (0.00 sec)
Oceanbase>select insert('Quadratic',-2,100,'What'), insert('Quadratic',7,3,'What'),
-> insert('Quadratic',-1,3,'What'), insert('Quadratic',10,3,'What'), insert('Quadratic',5,-1,''),
-> insert('Quadratic',7,-1,'What')\G;
*************************** 1. row ***************************
insert('Quadratic',-2,100,'What'): Quadratic
insert('Quadratic',7,3,'What'): QuadraWhat
insert('Quadratic',-1,3,'What'): Quadratic
insert('Quadratic',10,3,'What'): Quadratic
insert('Quadratic',5,-1,''): Quad
insert('Quadratic',7,-1,'What'): QuadraWhat
1 row in set (0.01 sec)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。