需要有一个Oracle SQL查询,该查询将找出特定字段值连续字符出现次数超过2次的行
Field1
---------------
asdfgh
asdewr
aaasdf
sssrty
sswasv
vvvruy8
<<this keeps going>>
从上面,只需要在下面选择:
aaasdf
sssrty
vvvruy8
答案 0 :(得分:3)
尝试使用regexp_like
,如下所示:
select field from
(select 'asdaaa' field from dual
union all select 'asdxx' from dual
union all select 'asdxxx' from dual
union all select 'asd1111' from dual)
WHERE REGEXP_LIKE(field, '(.+?)\1{2,}?')
返回具有3个或更多次出现的连续字符的字符串:
FIELD
-------
asdaaa
asdxxx
asd1111
3 rows selected.
答案 1 :(得分:1)
按这样的字母查询:
SELECT fieldname
FROM tablename
WHERE SUBSTR(fieldname, 1, 1) = SUBSTR(fieldname, 2, 1)
AND SUBSTR(fieldname, 1, 1) = SUBSTR(fieldname, 3, 1);