OceanBase SET NAMES

2021-06-29 14:38 更新

描述

该语句用来设置当前连接的数据库的字符集编码。

格式

SET NAMES 'charset_name' [COLLATE 'collation_name']

参数解释

参数

描述

charset_name

指定字符集

collation_name

指定字符集排序规则。如未指定,则使用字符集默认排序规则。

说明 
该语句将三个会话系统变量​ character_set_client ​, ​character_set_connection​ 和 ​character_set_results​ 设置为给定的字符集。将 ​character_set_connection​ 设置为 ​charset_name ​,将 ​collation_connection​设置为 ​charset_name​ 的默认排序规则。

示例

  • 设置数据库的字符集和排序规则。
OceanBase(admin@test)>SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci';
Query OK, 0 rows affected (0.00 sec)

OceanBase(admin@test)>show variables like 'character_set_c%';
+--------------------------+---------+
| Variable_name            | Value   |
+--------------------------+---------+
| character_set_client     | utf8mb4 |
| character_set_connection | utf8mb4 |
+--------------------------+---------+
2 rows in set (0.01 sec)

OceanBase(admin@test)>show variables like 'collation_connection';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
+----------------------+--------------------+
1 row in set (0.05 sec)


OceanBase(admin@test)>SET NAMES 'gbk';
Query OK, 0 rows affected (0.02 sec)

OceanBase(admin@test)>show variables like 'character_set_c%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| character_set_client     | gbk   |
| character_set_connection | gbk   |
+--------------------------+-------+
2 rows in set (0.01 sec)


OceanBase(admin@test)>show variables like 'collation_connection';
+----------------------+----------------+
| Variable_name        | Value          |
+----------------------+----------------+
| collation_connection | gbk_chinese_ci |
+----------------------+----------------+
1 row in set (0.01 sec)
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号