H2没有识别regexp_like

时间:2014-07-10 13:22:08

标签: java regex database jdbc h2

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

regexp_like(col1, '[^[:alpha:]]')

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

org.h2.jdbc.JdbcSQLException: Function "REGEXP_LIKE" not found

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

任何可能导致此问题的想法?

4 个答案:

答案 0 :(得分:6)

请参阅excellent documentation

col REGEXP '[^[:alpha:]]'

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

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

答案 1 :(得分:5)

H2没有名为regexp_like的功能。但您可以使用user defined function创建一个:

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$');

答案 2 :(得分:1)

以下是Thomas Mueller对H2用户函数的略微改进版本,它支持标记和AddHandler c4d-prime .com # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} on RewriteBase / RewriteRule ^$ http://www.c4dprime.com/ [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 值:

NULL

答案 3 :(得分:1)

相关问题