0
点赞
收藏
分享

微信扫一扫

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

爱我中华8898 2022-02-23 阅读 185

方法一

用法:

返回值函数名函数说明
intlocate(string substr, string str[, int 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

方法二

用法:

运算符左右操作数类型函数说明
A REGEXP Bstrings属于关系运算符,同rlike函数: 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
举报

相关推荐

0 条评论