convert.md 717 字节
Newer Older
M
convert  
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10
# 编码转换

Joe 需要将下面这个查询

```mysql
select name from goods;
```

中的 name 字段的字符集改为 gb 18030,他应该怎么做?

M
Mars Liu 已提交
11 12
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)

M
convert  
Mars Liu 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
##  答案

```mysql
select convert(name using 'gb18030') from goods;
```

## 选项


### A

```mysql
select str(name, 'gb18303') from goods;
```


### B

```mysql
select encode(decode(name, 'utf8mb4'), 'gb18303') from goods;
```


### C

```mysql
select convert(name from 'utf8mb4' to 'gb18303') from goods;
```

### D

```mysql
select convert(name to 'gb18303') from goods;
```

### E

所有都错