I have some ticket numbers that may have numbers and letters 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With