Link to home
Start Free TrialLog in
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.
Avatar of sakthikumar
sakthikumar

ASKER

Question should be "how to convert a comma separated value into multiple rows
Avatar of 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
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you SDS TUBER. I am 100% satisfied with your answer.