在 Hive 中是否有任何类似于在 Oracle 中解码的功能? [英] is there any function in Hive similiar to decode in Oracle?

查看:26
本文介绍了在 Hive 中是否有任何类似于在 Oracle 中解码的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个像 Oracle 的 DECODE 一样工作的字符串函数具有单列 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

我希望结果是这样的:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆