Hive中有什么功能可以在Oracle中进行解码? [英] is there any function in Hive similiar to decode in Oracle?
本文介绍了Hive中有什么功能可以在Oracle中进行解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个类似于Oracle的DECODE的字符串函数具有表 tab
和一列 col
I'm looking for a string function that works like Oracle's DECODE
Having table tab
with a single column col
col
----
a
b
c
d
通过简单的查询:
select decode(col,'a',1,'b',2',9) dec from tab
我希望得到这样的结果:
I'd expect result like this:
dec
---
1
2
9
9
我在《语言手册》中没有找到任何内置功能.有没有可以模拟DECODE的UDF?
I haven't found any build-in function in Language Manual. Is there any UDF that can simulate DECODE?
我不想使用 case
子句.
致谢
帕维尔
推荐答案
您可以编写嵌套的 if
语句.
You could write a nested if
statement.
查询:
select col
, if(col='a', 1, if(col='b', 2, 9)) dec
from table
输出:
---------
col | dec
---------
a 1
b 2
c 9
d 9
这篇关于Hive中有什么功能可以在Oracle中进行解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文