Solved

How to get this query ?

Posted on 2014-04-24
4
263 Views
Last Modified: 2014-05-02
HI All,

i am using oracle 11g,

i have below table with data

emp_data .

emp_id         emp_loc

 

1                   x,y,z

1                   m,y,z

 

my requirement  is

required output

1            x

1             y

1             z

1             m
0
Comment
Question by:deve_thomos
4 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 40021908
try this

with 
  emp_data as (
    select 1 emp_id, 'x,y,z' emp_loc from dual
    union
    select 1 emp_id, 'm,y,z' emp_loc from dual
    ),
  emp_split as ( 
    select emp_id, regexp_substr(emp_loc, '[^,]+', 1, level) loc 
    from emp_data 
    connect by regexp_substr(emp_loc, '[^,]+', 1, level) is not null)
select distinct emp_id, loc from emp_split;    

Open in new window

0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40021911
try something like this

select empid,emp_loc from (
select empid, regexp_substr(emp_loc, '[^,]+', 1, level) emp_loc
    from emp_data
    connect by regexp_substr(emp_loc, '[^,]+', 1, level) is not null)
    group by empid,emp_loc

where emp_data is the table name...
0
 
LVL 8

Expert Comment

by:Ganapathi
ID: 40021957
Try using INSTR function
0
 
LVL 32

Accepted Solution

by:
awking00 earned 500 total points
ID: 40022499
select distinct emp_id, regexp_substr(emp_loc,'[^,]+',1,level) loc
from emp_data
connect by level <= 1 + length(emp_loc) - length(replace(emp_loc,','));
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with Oracle syntax 4 56
ORA-01008: not all variables bound. 6 38
Get the parent node - XMLTYPE 9 56
Oracle 10g - insert string with special characters 8 41
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to recover a database from a user managed backup
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

910 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

18 Experts available now in Live!

Get 1:1 Help Now