Solved

How to get this query ?

Posted on 2014-04-24
4
261 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 36

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 31

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.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

747 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

14 Experts available now in Live!

Get 1:1 Help Now