Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query to split comma separated values of a column in row and get the distinct values

user8744020Aug 29 2018 — edited Aug 30 2018

Hi,

I am writing a query to split comma separated values of a column in row and get the unique values. I was able to split the comma separated values but unable to get the distinct values.

Is there a way to get distinct values in the below query:

with t as (select distinct(DECODED) as str from lkv where lku_key =1234)

select rtrim(ltrim(regexp_substr(str,'[^,]+',1,level))) as val

from t

connect by regexp_substr(str,'[^,]+',1,level) is not null;

Example data and table details are below along with how the output should look :

Table name : lkv

Column name : decoded

pastedImage_1.png

Could you please let me know, what is wrong in the above query.

Thanks in advance.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2018
Added on Aug 29 2018
10 comments
9,597 views