0

我有这样的查询语句:

select t.*
  from T_ex_table t
 where regexp_like(t.note,
                   '^(.*[^[:digit:]]+)?([condition])([^[:digit:]]+.*)?$',
                   'n')

如果我在 jpa 中将它与 querydsl(com.querydsl) 一起使用(这是 scala,并不重要):

 @Query(value =
    "select t.*" +
      "  from T_PURCHASE t" +
      " where regexp_like(t.note," +
      "                   '^(.*[^[:digit:]]+)?([?1])([^[:digit:]]+.*)?$'," +
      "                   'n')", nativeQuery = true)
 def getByTrackingNo(trackingNo: String): Purchase

当我调试测试时,它总是抛出

为方法公共抽象 Purchase PurchaseRepository.getByTrackingNo(java.lang.String) 使用命名参数,但在带注释的查询中找不到参数 'trackingNo' 'select t.pt_note, t.tracking_no from T_EC_PURCHASE t where regexp_like(t.pt_note, '^( . [^[:digit:]]+)?({?1})([^[:digit:]]+. )?$', 'n')'!

我错过了什么,我该如何解决。

4

1 回答 1

2

Maybe try to move full regexp to the param method? and build it before. for example :
@Query(value = "select t.* from T_PURCHASE t where regexp_like(t.note, ?1, 'n')", nativeQuery = true)
Where ?1 - yours fully build regexp with required parameters.

于 2018-05-08T05:57:11.747 回答