Home » SQL & PL/SQL » SQL & PL/SQL » split csv to multiple records (Oracle 11g)
split csv to multiple records [message #587798] Tue, 18 June 2013 12:51 Go to next message
rajivn786
Messages: 161
Registered: January 2010
Senior Member
Hi,

I have a small requirement...


Create table temp_a (source_code varchar2(100), target_code varchar2(1000));

Insert into temp_a values ('1','002.0 AND 002.9');
Insert into temp_a values ('2','729.90 AND 079.99 AND 002.9');

Output : 

  1 002.0
  1 002.9
  2 729.90
  2 079.99
  2 002.9



So, once we get the output, it needs to be joined to another table..
I did google search, but most of them are retuning collections/arrays as output. Not sure how I join the collection with the table.


create or replace function splits
(
    p_list varchar2,
    p_del varchar2 
) return split_tbl pipelined
is
    l_idx    pls_integer;
    l_list    varchar2(32767) := p_list;

    l_value    varchar2(32767);
begin
    loop
        l_idx := instr(l_list,p_del);
        if l_idx > 0 then
            pipe row(substr(l_list,1,l_idx-1));
            l_list := substr(l_list,l_idx+length(p_del));

        else
            pipe row(l_list);
            exit;
        end if;
    end loop;
    return;
end splits;



Thanks.
Re: split csv to multiple records [message #587799 is a reply to message #587798] Tue, 18 June 2013 13:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Just execute:
select * from table(splits(...));
and you will know the answer.

Regards
Michel
Re: split csv to multiple records [message #587803 is a reply to message #587799] Tue, 18 June 2013 14:19 Go to previous messageGo to next message
rajivn786
Messages: 161
Registered: January 2010
Senior Member
Thanks..It works
Re: split csv to multiple records [message #587809 is a reply to message #587803] Tue, 18 June 2013 14:39 Go to previous message
Michel Cadot
Messages: 68767
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You could post the solution for future readers.

Regards
Michel
Previous Topic: SQL QUERY ERROR help
Next Topic: data load
Goto Forum:
  


Current Time: Sun Aug 31 02:08:44 CDT 2025