6

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

3 Answers 3

9

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')
1
  • but this ignores the index probably set on the columns?!
    – dermoritz
    Commented Feb 2, 2012 at 8:53
3

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
  • Good finding! not sure what is the performance gain though opposed to the simple UPPER to the search query
    – Marc
    Commented Dec 25, 2011 at 1:44
  • A better link would be useful here. That link now takes me to a main page, and searching for the page didn't find it. Commented Oct 31, 2017 at 6:49
  • Sorry, that blog entry is close to 10 years old, and it looks like Oracle have removed it. :( You can still find it here, for now: bigip-blogs-cms-adc.oracle.com/kah/entry/… Or, try using archive.org to access the page as it was in 2009... Commented Oct 31, 2017 at 13:38
0

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+"%"+"'");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.