Solved

how to convert comma separated row into columns

Posted on 2013-12-29
6
1,300 Views
Last Modified: 2014-01-05
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.
0
Comment
Question by:sakthikumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:sakthikumar
ID: 39744659
Question should be "how to convert a comma separated value into multiple rows
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39745429
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.
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 500 total points
ID: 39745442
Easier than using faux-xml,  simply use str2tbl function

see here...


http://www.experts-exchange.com/Database/Oracle/Q_26552023.html


WITH t
     AS (SELECT value_x
           FROM gcb_dba.gcb_admin s
          WHERE s.item = 'Delivery Mode')
SELECT x.COLUMN_VALUE
  FROM t, TABLE(str2tbl(t.value_x)) x


this should work in 9.2.0.1 and above
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:sakthikumar
ID: 39745493
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
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39745507
sorry I missed the error but thanks for repeating it.

If you're getting that then you've encountered a bug.
You can search oracle support to see if there is an old patch that might help.
It's not supported anymore so you won't get new bug fixes, so you'll either need to upgrade or use alternate syntax as posted above.
0
 

Author Closing Comment

by:sakthikumar
ID: 39758639
Thank you SDS TUBER. I am 100% satisfied with your answer.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question