Solved

how to convert comma separated row into columns

Posted on 2013-12-29
6
1,255 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
  • 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 73

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 73

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 73

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now