Parameter in like clause JPQL

后端 未结 8 1329
盖世英雄少女心
盖世英雄少女心 2020-11-27 03:20

I am trying to write a JPQL query with a like clause:

LIKE \'%:code%\'

I would like to have code=4 and find

455
554
646
...
         


        
8条回答
  •  隐瞒了意图╮
    2020-11-27 04:12

    You could use the JPA LOCATE function.

    LOCATE(searchString, candidateString [, startIndex]): Returns the first index of searchString in candidateString. Positions are 1-based. If the string is not found, returns 0.

    FYI: The documentation on my top google hit had the parameters reversed.

    SELECT 
      e
    FROM 
      entity e
    WHERE
      (0 < LOCATE(:searchStr, e.property))
    

提交回复
热议问题