字符串连接运算符||在配置单元中抛出错误

问题描述

我正在尝试使用连接运算符 || 连接表中的字符串列并抛出错误

Here is the query: select "Bob"||'~'||"glad" from table

its throwing error as : ParseException - cannpt recognize input near '|' '"~"' '|' in expression specification

它适用于 concat 函数,但不适用于 concat 运算符。

select concat("bob","~","glad") from table - its working

我使用的是 hive 2.1 版,谁能告诉我为什么这个操作符不起作用?

谢谢,巴布

解决方法

Hive 不支持 concat 运算符 ||,它的 oracle 语法。请使用 concat 函数连接多个值。您可以使用 concat_ws 与分隔符连接。
连接

select concat ('this','~','is','hello','world');
Output : this~is~hello~world
select concat_ws ('~','world','not','enough');
Output : hello~world~is~not~enough