Files
oceanbase/docs/docs-cn/7.developer-guide-1/2.connect-to-the-oceanbase-database/6.query-table-data/6.use-operators-and-functions-in-queries/3.use-a-string-connector-in-a-query.md
2022-02-10 14:51:49 +08:00

1.1 KiB

查询中使用字符串连接符

MySQL 租户的字符串连接函数是 concat 、 concat_ws, '||' 默认是表示逻辑运算符`或`。

如查看 MySQL 租户下的客户姓名,SQL语句如下:

obclient> SELECT concat_ws(' ', c_first, c_last) full_name FROM cust ORDER BY c_last LIMIT 2;

+---------------------------+
| full_name                 |
+---------------------------+
| fvBZoeIV2uJh7 ABLEABLEESE |
| dHmIgRV1IsC ABLEABLEOUGHT |
+---------------------------+
2 rows in set (0.01 sec)

如果把 MySQL 租户下的变量 sql_mode 值增加一个选项 PIPES_AS_CONCAT ,则 '||' 也会当作字符串连接符。SQL语句如下:

obclient> SET SESSION sql_mode='PIPES_AS_CONCAT,STRICT_TRANS_TABLES,STRICT_ALL_TABLES';
obclient> SELECT c_first || ' ' || c_last  full_name FROM cust ORDER BY c_last LIMIT 2;
+---------------------------+
| full_name                 |
+---------------------------+
| fvBZoeIV2uJh7 ABLEABLEESE |
| dHmIgRV1IsC ABLEABLEOUGHT |
+---------------------------+
2 rows in set (0.01 sec)