Solved

How to get this query ?

Posted on 2014-04-24
4
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 38

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
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 how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

636 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