今天在hive中插入数据的时候使用了中文,结果select出来的全是乱码,经测试以下方法能够得以解决,特此记录
select * from dept;
+----------+----------------+--+
| dept.id | dept.position |
+----------+----------------+--+
| 1 | ceo |
| 1 | 保安 |
| 3 | 保洁 |
| 4 | 会计 |
| 6 | 员工 |
| 7 | 前台 |
| 8 | 律师 |
| 5 | 员工 |
+----------+----------------+--+
为防止乱码,我们可以采用以下insert方法:
insert into dept select decode(binary('1'),'utf-8'),decode(binary('ceo'),'utf-8');
insert into dept select decode(binary('1'),'utf-8'),decode(binary('保安'),'utf-8');
insert into dept select decode(binary('3'),'utf-8'),decode(binary('保洁'),'utf-8');
insert into dept select decode(binary('4'),'utf-8'),decode(binary('会计'),'utf-8');
insert into dept select decode(binary('5'),'utf-8'),decode(binary('员工'),'utf-8');
insert into dept select decode(binary('6'),'utf-8'),decode(binary('员工'),'utf-8');
insert into dept select decode(binary('7'),'utf-8'),decode(binary('前台'),'utf-8');
insert into dept select decode(binary('8'),'utf-8'),decode(binary('律师'),'utf-8');