H2没有识别regexp_like

Ste*_*101 2 java regex database jdbc h2

我编写了一个在Oracle数据库上运行的查询,该数据库使用函数REGEXP_LIKE来过滤查询中的某些行.具体的函数调用是

regexp_like(col1, '[^[:alpha:]]')
Run Code Online (Sandbox Code Playgroud)

问题是当我在H2上运行查询时出现以下错误:

org.h2.jdbc.JdbcSQLException: Function "REGEXP_LIKE" not found
Run Code Online (Sandbox Code Playgroud)

如果我使用SQLDeveloper工具直接在Oracle数据库上运行查询,它将按预期返回.

可能导致这种情况的任何想法?

Joo*_*gen 6

查看优秀的文档.

col REGEXP '[^[:alpha:]]'
Run Code Online (Sandbox Code Playgroud)

通常,SQL变体使用函数或命名运算符.

以上具体的正则表达式是否有效我不知道.一个人应该能够依赖java正则表达式.


Tho*_*ler 6

H2没有名为的函数regexp_like。但是您可以使用用户定义的函数创建一个:

create alias regexp_like as 
$$ boolean regexpLike(String s, String p) { return s.matches(p); } $$;

drop table test;
create table test(id int, name varchar(2555));
insert into test values(1, 'Steven');
insert into test values(2, 'Stefan');
select * from test where regexp_like(name, '^Ste(v|ph)en$');
Run Code Online (Sandbox Code Playgroud)