convert.md 810 字节
Newer Older
M
convert  
Mars Liu 已提交
1 2 3 4
# 编码转换

Joe 需要将下面这个查询

fix bug  
张志晨 已提交
5
```sql
M
convert  
Mars Liu 已提交
6 7 8 9 10
select name from goods;
```

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

M
Mars Liu 已提交
11 12
<hr/>

F
feilong 已提交
13
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill){target="_blank"}。
F
feilong 已提交
14

F
feilong 已提交
15 16
* `show databases;` 列出所有数据库
* `show tables;` 列出所有表
M
Mars Liu 已提交
17

M
convert  
Mars Liu 已提交
18 19
##  答案

fix bug  
张志晨 已提交
20
```sql
21 22
select convert(name using 'gb18030') 
from goods;
M
convert  
Mars Liu 已提交
23 24 25 26 27 28 29
```

## 选项


### A

fix bug  
张志晨 已提交
30
```sql
31 32
select str(name, 'gb18303') 
from goods;
M
convert  
Mars Liu 已提交
33 34 35 36 37
```


### B

fix bug  
张志晨 已提交
38
```sql
39 40
select encode(decode(name, 'utf8mb4'), 'gb18303') 
from goods;
M
convert  
Mars Liu 已提交
41 42 43 44 45
```


### C

fix bug  
张志晨 已提交
46
```sql
47 48
select convert(name from 'utf8mb4' to 'gb18303') 
from goods;
M
convert  
Mars Liu 已提交
49 50 51 52
```

### D

fix bug  
张志晨 已提交
53
```sql
54 55
select convert(name to 'gb18303') 
from goods;
M
convert  
Mars Liu 已提交
56 57 58 59 60
```

### E

所有都错