Tuesday, May 21, 2013

Function Based Index



A clob column in a table cannot be directly used in the search. ( Again, who would search based on a clob?  This is a one-off case )
Query would throw an exception if we do so.
select * from clob_table where clob_column =
ORA-00932: inconsistent datatypes: expected - got CLOB

As a workaround, we can run the query based on a function over the clob column
select * from clob_table where to_char(clob_column) =<> ;

Though the above query runs fine, it would make a full table scan.
This brings us to the functional index.
CREATE INDEX INDEX_CLOB ON clob_table (to_char("clob_column") ASC)

With this index there wouldnt be any full table scan thus the cost of the query can be reduced.

No comments: