Case-insensitive Query
I have some ticket numbers that may have numbers and let开发者_如何学JAVAters mixed. I'll be passing in the ticketNumberIds
into this method (user input) and I want it to query against the Oracle database and have the query pick up tickets that differ by upper and lower cases.
How do I make the following a case-insensitive query?
public List<TicketDO> getTicketDOsById(final List<String> ticketNumberIds) {
String myQuery = "from TicketDO t where t.ticketNumberId in (:ticketNumberIds)";
return getEntityManager().createQuery(myQuery).setParameter("ticketNumberIds", ticketNumberIds)
.getResultList();
}
You can use UPPER to perform case insensitive queries.
public List<TicketDO> getTicketDOsById(final List<String> ticketNumberIds) {
String myQuery = "from TicketDO t where UPPER(t.ticketNumberId) in (:ticketNumberIds)";
List<String> upperNumbers = new ArrayList<String>();
for (String number : ticketNumberIds) {
upperNumbers.add(number.toUppercase());
}
return getEntityManager().createQuery(myQuery).setParameter("ticketNumberIds", upperNumbers)
.getResultList();
}
精彩评论