select * from quotes_in;
QUOTE_TXT
------------------------------------------------------------------------------------------------------------------------------------
15/09/2008 10:00:00:15/09/2008 10:01:00:15/09/2008 10:02:00:15/09/2008 10:03:00:15/09/2008 10:04:00:15/09/2008 10:05:00
44.22:44.2:44.165:44.175:44.17:44.2
44.24:44.21:44.2:44.19:44.235:44.21
44.2:44.16:44.155:44.15:44.165:44.18
44.21:44.175:44.17:44.185:44.2:44.18
14566:6520:15562:14410:33259:8652
15/09/2008 11:00:00:15/09/2008 11:01:00:15/09/2008 11:02:00:15/09/2008 11:03:00:15/09/2008 11:04:00:15/09/2008 11:05:00:15/09/2008 11:06:00 (<-- Sorry, because this row has 7 dates/times, it was too long to display on one line...it wrapped onto the next line.)
44.32:44.3:44.165:44.175:44.17:44.3:44.35
44.34:44.31:44.3:44.19:44.335:44.31:44.36
44.3:44.16:44.155:44.15:44.165:44.18:44.20
44.31:44.175:44.17:44.185:44.3:44.18:44.23
14566:6520:15562:14410:33259:8652:10999
declare
rec_type number := 0;
type nums is table of number index by binary_integer;
beg_loc nums;
len nums;
curr_delim_loc nums;
next_delim_loc nums;
hold_quote quotes_in.quote_txt%type;
num_entries number;
type y is record (a quotes%rowtype);
type x is table of y index by binary_integer;
z x;
function get_curr_num (str_in varchar2,which_num number) return number is
begin
curr_delim_loc(which_num) := instr(str_in,':',1,which_num);
next_delim_loc(which_num) := instr(str_in,':',1,which_num+1);
return to_number(substr(str_in,curr_delim_loc(which_num)+1,next_delim_loc(which_num)-curr_delim_loc(which_num)-1));
end;
procedure insert_rows is
begin
for i in 1..num_entries loop
insert into quotes values(z(i).a.time,z(i).a.open,z(i).a.high,z(i).a.low,z(i).a.close,z(i).a.volume);
end loop;
end;
begin
for r in (select * from quotes_in) loop
rec_type := rec_type + 1;
hold_quote := ':'||r.quote_txt||':';
if rec_type = 1 then
num_entries := length(hold_quote) - length(replace(hold_quote,' ',null));
for i in 1..num_entries loop
z(i).a.time := to_date(substr(hold_quote,((i-1)*20)+2,19),'dd/mm/yyyy hh24:mi:ss');
end loop;
elsif rec_type = 2 then
for i in 1..num_entries loop
z(i).a.open := get_curr_num(hold_quote,i);
end loop;
elsif rec_type = 3 then
for i in 1..num_entries loop
z(i).a.high := get_curr_num(hold_quote,i);
end loop;
elsif rec_type = 4 then
for i in 1..num_entries loop
z(i).a.low := get_curr_num(hold_quote,i);
end loop;
elsif rec_type = 5 then
for i in 1..num_entries loop
z(i).a.close := get_curr_num(hold_quote,i);
end loop;
elsif rec_type = 6 then
for i in 1..num_entries loop
z(i).a.volume := get_curr_num(hold_quote,i);
end loop;
rec_type := 0;
Insert_rows;
end if;
end loop;
commit;
end;
/
select to_char(time,'dd/mm/yyyy hh24:mi:ss')time,open,high,low,close,volume from quotes;
TIME OPEN HIGH LOW CLOSE VOLUME
------------------- ---------- ---------- ---------- ---------- ----------
15/09/2008 10:00:00 44.22 44.24 44.2 44.21 14566
15/09/2008 10:01:00 44.2 44.21 44.16 44.175 6520
15/09/2008 10:02:00 44.165 44.2 44.155 44.17 15562
15/09/2008 10:03:00 44.175 44.19 44.15 44.185 14410
15/09/2008 10:04:00 44.17 44.235 44.165 44.2 33259
15/09/2008 10:05:00 44.2 44.21 44.18 44.18 8652
15/09/2008 11:00:00 44.32 44.34 44.3 44.31 14566
15/09/2008 11:01:00 44.3 44.31 44.16 44.175 6520
15/09/2008 11:02:00 44.165 44.3 44.155 44.17 15562
15/09/2008 11:03:00 44.175 44.19 44.15 44.185 14410
15/09/2008 11:04:00 44.17 44.335 44.165 44.3 33259
15/09/2008 11:05:00 44.3 44.31 44.18 44.18 8652
15/09/2008 11:06:00 44.35 44.36 44.2 44.23 10999
13 rows selected.
(i.e., 6 rows for the first time period and 7 rows for the second time period.)