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

Sara
  • 612
  • 5
  • 21

3 Answers3

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')
MikeD
  • 8,861
  • 2
  • 28
  • 50
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

Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
  • Good finding! not sure what is the performance gain though opposed to the simple UPPER to the search query – Marc Dec 25 '11 at 01: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. – MiguelMunoz Oct 31 '17 at 06: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: https://bigip-blogs-cms-adc.oracle.com/kah/entry/derby_10_5_preview_generated Or, try using archive.org to access the page as it was in 2009... – Bryan Pendleton Oct 31 '17 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+"%"+"'");
Vector
  • 3,066
  • 5
  • 27
  • 54