在HIVE中查找功能 [英] Find function in HIVE
本文介绍了在HIVE中查找功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查一个字段是否包含字符串.
I want to check if a field contains a string.
我想要一个看起来像这样的函数:
I want a function that would look like this:
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"
我正在寻找一个函数,该函数标识包含指定的字符串以及该字符串从什么位置开始.
I am looking for a function that identifies that the specified string is contained and at what position the string starts.
return
------
-1
-1
15
推荐答案
内置的locate
函数几乎可以完全满足您的需求,除了输入内容会返回
The built in locate
function does nearly exactly what you need except that for your input, it would return
return
------
0
0
16
由于它从1开始编制索引,因此您所需要做的就是:
Since it indexes from 1. So all you need to do is:
Select locate("string_to_find","ahh finally xxxstring_to_findxxx is here") -1; --returns 15
Select locate("string_to_find","foo") -1; --returns -1
这篇关于在HIVE中查找功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文