How to make WHERE clause case insensitive: From SQL Server querying Oracle linked server

Peter Bridger picture Peter Bridger · Sep 7, 2011 · Viewed 32.4k times · Source

We have a MS SQL Server 2005 installation that connects to an Oracle database through a linked server connection.

Lots of SELECT statements are being performed through a series of OPENQUERY() commands. The WHERE clause in the majority of these statements are against VARCHAR columns.

I've heard that if the WHERE clause is case sensitive, it can have a big impact on performance.

So my question is, how can I make sure that the non-binary string WHERE clauses are being performed in a case insensitive way for maximum performance?

Answer

Branko Dimitrijevic picture Branko Dimitrijevic · Sep 7, 2011

It's actually the other way around:

Case sensitive...

WHERE column = :criteria

...will use index on column directly and perform well.

Case insensitivity typically requires something like this...

WHERE UPPER(column) = UPPER(:criteria)

...which does not use index on column and performs poorly (unless you are careful and create a functional index on UPPER(column)).

I'm not sure whether OPENQUERY() changes anything, but from purely Oracle perspective both case-sensitive and insensitive queries can be made performant, with the insensitive ones requiring special care (functional index).