栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

在Hive中判断字符串中是否包含指定子字符串

在Hive中判断字符串中是否包含指定子字符串

方法一 : like 1.1 传统的 like 查找:
select 'this 是 china' like('%是%');	--true
select 'this 是 china' like '%是%';		--true

select 'this 是 china' like('%否%');	--false
select 'this 是 china' like '%否%';		--false
1.2 基于正则表达式的查找:

参考java正则表达式的用法:

select 'this 是 china' rlike('是');		--true

select 'foobar' rlike('foo');			--true	
select 'foobar' rlike('bar');			--true
select 'foobar' rlike('^f.*r$');		--true
方法二 : locate

用法:

返回值函数名函数说明
intlocate(string substr, string str[, int pos])[一、参数说明: 参数1-substr: 待查找的字符子串; 参数2-str: 原始字符串; 参数3-pos: 指定位置,将查找在此位置及之后位置第一次出现指定字符串的位置.] …[英文说明: Returns the position of the first occurrence of substr in str after position pos.]

使用案例:

select locate('i','this is china'); 	--3
select locate('i','this is china',4);	--6
select locate('i','this is china',7);	--11
方法三 : regexp

用法:

运算符左右操作数类型函数说明
A REGEXP Bstrings属于关系运算符,同rlike函数, 根据java正则表达式判断. [一、参数说明: 参数1-A: 原始字符串; 参数2-B: 待比较的子字符串] …[英文说明:NULL if A or B is NULL, TRUE if any (possibly empty) substring of A matches the Java regular expression B, otherwise FALSE. For example, ‘foobar’ RLIKE ‘foo’ evaluates to TRUE and so does ‘foobar’ RLIKE ‘^f.*r$’.]
select 'this 是 china' regexp('是'); --true

--以下2种写法等价
select 'this 是 china' regexp('否'); --false
select 'this 是 china' regexp '否';  --false
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/745791.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号