在 HIVE 中查找函数

2024-04-06

我想检查一个字段是否包含字符串。

我想要一个如下所示的函数:

FIND("string_to_find",field_to_search)

我的数据如下所示:

field_to_search
---------------
"no match in this string"
"record 2 has no matches"
"ahh finally xxxstring_to_findxxx is here"

我正在寻找一个函数来标识包含指定的字符串以及该字符串在什么位置开始。

return
------
-1
-1
15

内置的locate函数几乎完全满足您的需要,除了您的输入,它会返回

return
------
0
0
16

由于它的索引从 1 开始。所以您需要做的就是:

Select locate("string_to_find","ahh finally xxxstring_to_findxxx is here") -1; --returns 15
Select locate("string_to_find","foo") -1; --returns -1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 HIVE 中查找函数 的相关文章

随机推荐