Case insensitive search in Java DB (Derby)

2019-04-29 07:25发布

问题:

I'm using Derby and I can't find a way to do case insensitive search.

For example, I have a table that I'm searching that contains "Hello" but I put a search query in for "hello" and at the moment I won't get a result, but I want to.

I can't find the correct syntax for it.

Sara

回答1:

You can use the UPPER() or LOWER() SQL functions on both your search argument and the field, like in

SELECT *
FROM   mytab
WHERE  UPPER(lastname) = UPPER('McDonalds')


回答2:

The most common way to do this is to use generated columns. Here's a nice writeup from one of the Derby developers: http://blogs.oracle.com/kah/entry/derby_10_5_preview_generated