Solved

How to get this query ?

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

821 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