Then value remains free from the '%' sign. If you need to use it somewhere else in the same query simply use another parameter name other than 'code' .
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))
I don't know if I am late or out of scope but in my opinion I could do it like:
String orgName = "anyParamValue";
Query q = em.createQuery("Select O from Organization O where O.orgName LIKE '%:orgName%'");
q.setParameter("orgName", orgName);
Use JpaRepository or CrudRepository as repository interface:
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Integer> {
@Query("SELECT t from Customer t where LOWER(t.name) LIKE %:name%")
public List<Customer> findByName(@Param("name") String name);
}
@Service(value="customerService")
public class CustomerServiceImpl implements CustomerService {
private CustomerRepository customerRepository;
//...
@Override
public List<Customer> pattern(String text) throws Exception {
return customerRepository.findByName(text.toLowerCase());
}
}