问题
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
回答3:
This is really a late answer which I am not sure is the best way to manage the the process of doing a case insensitive search on a Textarea in a Derby Database
We added our search results to a TableView so if you get two results returned then the user has at least the option to decide which result is of value.
String upper = "BIG";
String lower = "big";
ResultSet rs = stmnt.executeQuery("SELECT * FROM Child WHERE cEntry LIKE
'"+"%"+upper+"%"+"'OR cEntry LIKE'"+"%"+lower+"%"+"'");
来源:https://stackoverflow.com/questions/6084000/case-insensitive-search-in-java-db-derby