Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: My DBA says this can't be done!
> In article <8tpnl0h2nf75hqji3jaejcsst0qkrtjip9_at_4ax.com>, Mike wrote:
> > are you on 10g? If so, you could use the regular expressions: >
No, you aren't. I overlooked that. So here's something that should do it on 9.2 as well.
create table incoming_data (
d varchar2(50)
);
insert into incoming_data values ('96 1 13002000'); insert into incoming_data values ('62 1 00000300 04001000'); insert into incoming_data values ('62 1 00000300 04001000 12001700'); insert into incoming_data values ('62 1 '); insert into incoming_data values ('62 1 '); insert into incoming_data values ('62 1 07001500'); insert into incoming_data values ('62 1 06001800'); insert into incoming_data values ('31 1 21000600');
create or replace type table_of_vc as table of Varchar2(8); /
create or replace Function SplitLine(
p_line in Varchar2, p_delim in table_of_vc default table_of_vc(' '), p_min_length in Number default 3) return table_of_vc
v_split_pos number; v_split_from_pos number := 1; v_split_str varchar2(100); v_ret table_of_vc := table_of_vc();
begin
begin
select
pos , len into v_split_pos, v_delim_len
from (
select len, pos, row_number () over (order by pos) r from ( select length(column_value) len, instr(p_line,column_value,1) pos from table(p_delim) ) where pos > 0
exception
when no_data_found then
v_split_pos := 0;
when others then
return v_ret;
end;
while v_split_pos > 0 loop
v_split_str := substr
(p_line, v_split_from_pos, v_split_pos-v_split_from_pos);
if length(v_split_str) >= p_min_length then
v_ret.extend; v_ret(v_ret.count) := v_split_str;end if;
v_split_from_pos := v_split_pos + v_delim_len;
begin
select pos , len into v_split_pos, v_delim_len from ( select len, pos, row_number () over (order by pos) r from ( select length(column_value) len, instr(p_line,column_value,v_split_from_pos) pos from table(p_delim) ) where pos > 0 ) where r = 1; exception when no_data_found then v_split_pos := 0;
end loop;
v_split_str := substr(p_line,v_split_from_pos);
if length (v_split_str) >= p_min_length then
v_ret.extend;
v_ret(v_ret.count) := v_split_str;
end if;
return v_ret;
end SplitLine;
/
create view v_incoming_data as
select
substr (d,1,2) DaysOfWeek,
column_value tm
from incoming_data,
table (SplitLine(substr(d,5)));
select * from v_incoming_data;
-- Rene Nyffenegger http://www.adp-gmbh.ch/Received on Thu Sep 30 2004 - 13:48:35 CDT