Solved

How to get this query ?

Posted on 2014-04-24
4
266 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
PL/SQL Search for multiple strings 5 53
Performance issue with case statement in oracle 11G 7 60
'G_F01' is not a procedure or is undefined 3 24
Can't Access My Database 57 63
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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
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…

786 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