Avatar of sakthikumar
sakthikumar
 asked on

how to convert comma separated row into columns

I have a value like below

D@#Direct, I@#Indirect

First I want to separate this into two rows like below and get description based on value.
D@#Direct
I@#Indirect

in which Direct and Indirect are description for values I and D.

I used this query to extract the description which does not work in 10 g.

WITH T AS

(SELECT VALUE_X FROM gcb_dba.GCB_ADMIN S WHERE S.ITEM = 'Delivery Mode')

SELECT DESCR --INTO LV_DESCR

  FROM (SELECT SUBSTR(DESCR, 1,INSTR(DESCR, '@#') - 1) VALUE1,

               SUBSTR(DESCR, INSTR(descr, '@#') + 2) DESCR

          FROM (SELECT CAST(TRIM(EXTRACT(COLUMN_VALUE, '/e/text()')) AS

                            VARCHAR2(100)) DESCR

                  FROM T X,

                       TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE('<ROW><e>' || ---

                                                         REPLACE(value_x,

                                                                 ',',

                                                                '</e><e>') ||
                                                         '</e></ROW>'),
                                                 '//e')))))

                                                  WHERE VALUE1 = 'D';                                                

=================================

I can execute the below in 10g to convert a value into rows, by commenting some part.
but not execute as a whole to extract description. I am getting error
"end of file on communication channel"


WITH T AS

(SELECT VALUE_X FROM gcb_dba.GCB_ADMIN S WHERE S.ITEM = 'Delivery Mode')

SELECT DESCR --INTO LV_DESCR

  FROM (/*SELECT SUBSTR(DESCR, 1,INSTR(DESCR, '@#') - 1) VALUE1\*,

               SUBSTR(DESCR, INSTR(descr, '@#') + 2) DESCR*\

          FROM (*/SELECT CAST(TRIM(EXTRACT(COLUMN_VALUE, '/e/text()')) AS

                            VARCHAR2(100)) DESCR

                  FROM T X,

                       TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE('<ROW><e>' || ---

                                                         REPLACE(value_x,

                                                                 ',',

                                                                 '</e><e>') ||

                                                         '</e></ROW>'),

                                                 '//e'))))
 
==========================================================
Now I want to know why in 10g I am not able to execute the query
and any other alternative way to extract the description.
Oracle Database

Avatar of undefined
Last Comment
sakthikumar

8/22/2022 - Mon
sakthikumar

ASKER
Question should be "how to convert a comma separated value into multiple rows
Sean Stuber

10g doesn't tell very much

What is the version  ?  It's 4 numbers  like  10.1.2.3

>>> Now I want to know why in 10g I am not able to execute the query

What doesn't work about it?  Error? wrong results? no results? keyboard catches fire?

With no information to go on except -it-doesn't-work-  I'm going to assume it's because of loss of scope through nesting.  "value_x" isn't known after you pass it through 5 layers of nested functions.


Also, from your description it sounds like you're looking for 2 columns but your example shows only one.
SOLUTION
Sean Stuber

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sakthikumar

ASKER
I am getting error like below,
"end of file on communication channel"
mentioned the same in my initial post.

Version is below.

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE      10.2.0.5.0      Production
TNS for HPUX: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Sean Stuber

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sakthikumar

ASKER
Thank you SDS TUBER. I am 100% satisfied with your answer.