oracle中REGEXP_LIKE中使用CARET符号有什么区别?

Ran*_*guy 0 regex sql string oracle oracle11g

我是 REGEX 的新手。所以,我试过:

select * from ot.contacts where REGEXP_like(last_name,'^[A-C]');
Run Code Online (Sandbox Code Playgroud)

另外,我试过:

select * from ot.contacts where REGEXP_like(last_name,'[A-C]');
Run Code Online (Sandbox Code Playgroud)

他们都给了我输出,其中 last_name 以 A、b、c 开头,并且获取的记录数是相同的。你能告诉我什么时候可以看到使用这个插入符号的区别吗?

GMB*_*GMB 5

在此上下文中,^ 表示字符串的开头。

  • '^[A-C]' 在字符串的开头检查 A、B 或 C。

  • '[A-C]' 检查字符串中任意位置的 A、B 或 C。

根据您的数据集,两个表达式可能会或可能不会产生相同的输出。以下是结果集不同的示例:

last_name         | ^[A-C]   | [A-C] 
----------------- | -------  | ----- 
Arthur            | match    | match
Bill              | match    | match
Jean-Christophe   | no match | match
Run Code Online (Sandbox Code Playgroud)