Search This Blog

Friday, November 8, 2013

How to select DISTINCT on a CLOB field.

Lets consider a table 'PREFERENCES' with two values 'ID' and 'PREFERENCES'. Where id is a Number and preferences is a CLOB field.

      ID   PREFERENCES
---------- ---------------------------------------------
         1 Oracle 
         2 Oracle 
         6 MSSQL
         7 MySQL
         8 Oracle

 


Now  if you want to find out how many distinct values are there in the Preference column.You might try to use;



This will generate the following  SQL error:



If you then use



This will also generate error :-


as per the Error Description If you use



Still, an SQL Error will be thrown , which is

There are lot of ways to solve this problem.One of the simplest way is to increase the Buffer in the same sql . As displayed below.



This runs without error and gets you all the unique values of preferences column.

Happy Coding!!




No comments:

Post a Comment

My Blog List