Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Comma separated values to rows

User_B9XGOOct 15 2020 — edited Oct 27 2020

Hi All,
My requirement is to compare 2 columns in which one column has coma separated values and the other a number.
The below query changes the comma separated values to rows. But, I am unable to compare it. Can someone please help.

select regexp_substr(emp_num,'[^,]+',1,level) m
from dual
connect BY regexp_substr(emp_num, '[^,]+', 1, level) is not null;

/******************************/
create table test_cust (Emp_id number ,Emp_num varchar2(50) );
insert into test_cust (Emp_id ,Emp_num,) values (123,'1234,5678,4321');
insert into test_cust (Emp_id ,Emp_num,) values (234,'6789');
create table test_cust_child (Emp_id number, Emp_num number);
insert into test_cust_child (Emp_id ,Emp_num) values ('',1234);
insert into test_cust_child (Emp_id ,Emp_num) values ('',5678);
insert into test_cust_child (Emp_id ,Emp_num) values ('',4321);
insert into test_cust_child (Emp_id ,Emp_num) values ('',6789);
/*********************************/
update test_cust_child b
set Emp_id =
(select b.Emp_id from
test_cust a
where a.Emp_num = b.Emp_num);
/***********************************/

Thank you.

This post has been answered by Frank Kulash on Oct 16 2020
Jump to Answer
Comments
Post Details
Added on Oct 15 2020
14 comments
1,647 views