相关疑难解决方法(0)

如何使用CriteriaBuilder调用db函数

我有一个最终可能包含空格的字符串。我想用与 \t、\r、\n 匹配的正则表达式替换这些空格。替换后,我想调用 regexp_like (一个 oracle 函数)来匹配该字符串的字段。

我知道可以使用标准生成器调用数据库函数,如本链接中所述

我不太熟悉 java 中的正则表达式与 oracle 中的正则表达式之间的区别,也不熟悉如何将其拼凑在一起(我从未从 criteriabuilder 中调用过函数)。这是我的尝试步骤以及我在评论中陷入困境的地方

// first replace all spaces with regex for \s,\r,\t, value is the original string
value.replaceAll(" +", "[\\t\\n\\r]+")
// build the db function call expression, seems I cant do table.<String>get(field) and cant pass value as a string
Expression<String> regExp = cb.function("regexp_like", String.class, table.<String>get(field), value);
// now create a predicate not sure how
Predicate fieldMatch = cb.equal(...)
Run Code Online (Sandbox Code Playgroud)

这可能吗?

java hibernate hibernate-criteria

5
推荐指数
1
解决办法
1978
查看次数

Hibernate Regexp MySQL

我问这个问题以展示MySQL和Hibernate如何通过正则表达式相互配合。

问题:

SELECT * FROM table WHERE regexp column '\d'
Run Code Online (Sandbox Code Playgroud)

解:

转到我的答案。

希望这可以帮助。

regex mysql hibernate

4
推荐指数
1
解决办法
5238
查看次数

标签 统计

hibernate ×2

hibernate-criteria ×1

java ×1

mysql ×1

regex ×1