我想检查一个字段是否包含一个字符串。
我想要一个看起来像这样的函数:
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
关于在 HIVE 中查找函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31926318/