我想检查一个字段是否包含一个字符串。
我想要一个看起来像这样的函数:
FIND("string_to_find",field_to_search)
Run Code Online (Sandbox Code Playgroud)
我的数据如下所示:
field_to_search
---------------
"no match in this string"
"record 2 has no matches"
"ahh finally xxxstring_to_findxxx is here"
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个函数来标识包含指定的字符串以及字符串在什么位置开始。
return
------
-1
-1
15
Run Code Online (Sandbox Code Playgroud)
内置locate函数几乎完全符合你的需要,除了你的输入,它会返回
return
------
0
0
16
Run Code Online (Sandbox Code Playgroud)
因为它从 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
Run Code Online (Sandbox Code Playgroud)