oracle regexp_substr用%来提取类似于like条件的单词

q5lcpyga  于 2023-10-16  发布在  Oracle
关注(0)|答案(2)|浏览(117)

我在谷歌上搜索了一下,找不到regexp_substr的解决方案。

select *
from customer
where lower (comment) like '%m%g';

在评论中可以包含任何可能的句子,想象一下,偏头痛下一步是试图找到拿起这个词在新的列
我想具体这个词的任何相关的%imm%g%或%im%g%在小或大或混合字母像移民输出,移民(是的,它可以是一个错字),移民,移民

select a.*,
regexp_susbtr (comment, '.mmig+\w*|.mig+\w*') as selected
from customer a
where lower (comment) like %imm%g%'
or lower (comment) like %im%g%;

regexp_susbtr (comment,'.mmig+\w*|.mig+\w*' <<=只拾取小写字母,什么是正确的编码,拾取任何小,大或混合字母
where regexp_like(comment, 'immig|imig','i') <<=如果我是对的,这是类似于下面,不是吗?

where lower (comment) like %immig%'
or lower (comment) like %imig%;

下一个问题;
什么是%的替代方法,以查找regexp_substrregexp_like之间的任何字母mg
我正在使用Oracle SQL,感谢您的帮助

nwnhqdif

nwnhqdif1#

select a.*,
       regexp_susbtr (comment, '.mmig+\w*|.mig+\w*') as selected
from   customer a
where  lower (comment) like %imm%g%'
or     lower (comment) like %im%g%;

regexp_susbtr (comment,'.mmig+\w*|.mig+\w*' <<=只拾取小写字母,什么是正确的编码,拾取任何小,大或混合字母
请参阅REGEXP_SUBSTR文档

...
match_param参数记录为:

  • match_param是数据类型为VARCHAR2CHAR的字符表达式,允许您更改函数的默认匹配行为。

match_param的值可以包含以下一个或多个字符:

  • 'i'指定不区分大小写的匹配,即使条件的确定排序规则是区分大小写的。

因此,您需要:

SELECT a.*,
       REGEXP_SUBSTR(comment, '\w*mig\w*', 1, 1, 'i') AS selected
FROM   customer a
WHERE  REGEXP_LIKE(comment, 'im\w*?g', 'i');

其中:

  • \w*mig\w*将匹配零个或多个(尽可能多的)单词字符,然后是子字符串mig,然后是零个或多个(尽可能多的)单词字符,'i'匹配参数使匹配不区分大小写。
  • 'im\w*?g'匹配子串im,然后匹配零个或多个单词字符(尽可能少),然后匹配g子串,'i'匹配参数使匹配不区分大小写。

什么是%的替代方法,以查找regexp_substrregexp_like之间的任何字母mg
如果你想要单词字符az09在任何情况下和_下划线,那么使用类似Perl的\w模式。
如果你只需要字母字符,那么使用POSIX字符类[[:alpha:]][a-zA-Z][a-z],不区分大小写。
对于字母字符:

SELECT a.*,
       REGEXP_SUBSTR(comment, '[[:alpha:]]*mig[[:alpha:]]*', 1, 1, 'i') AS selected
FROM   customer a
WHERE  REGEXP_LIKE(comment, 'im[[:alpha:]]*?g', 'i');

或:

SELECT a.*,
       REGEXP_SUBSTR(comment, '[a-z]*mig[a-z]*', 1, 1, 'i') AS selected
FROM   customer a
WHERE  REGEXP_LIKE(comment, 'im[a-z]*?g', 'i');
5n0oy7gb

5n0oy7gb2#

这是一种选择;看看有没有用
一些样本数据:

SQL> with customer (col) as
  2    (select 'I am not an immigrant'                         from dual union all
  3     select 'I want immigration to be found'                from dual union all
  4     select 'Who is "imigrant"?'                            from dual union all
  5     select 'Yep, that is immigration we are talking about' from dual union all
  6     select 'What? IMMIGRATION on TV?'                      from dual union all
  7     select 'Imagine all the people'                        from dual union all
  8     select 'Awful migraine in my head'                     from dual union all
  9     select 'No such word here'                             from dual
 10    )

查询方式:

11  select col,
 12    regexp_substr(col, 'im.*g\w+', 1, 1, 'i') result
 13  from customer
 14  where lower(col) like '%im%g%';

COL                                           RESULT
--------------------------------------------- ---------------------------------------------
I am not an immigrant                         immigrant
I want immigration to be found                immigration
Who is "imigrant"?                            imigrant
Yep, that is immigration we are talking about immigration
What? IMMIGRATION on TV?                      IMMIGRATION
Imagine all the people                        Imagine

6 rows selected.

SQL>

相关问题