PAY TTIME
-------------------------------------------------- -----------
a 2001-12-12 15:49:10
a 2001-12-12 15:49:11
a 2001-12-12 15:49:11
a 2001-12-12 15:49:12
a 2001-12-12 15:49:12
b 2001-12-12 15:49:24
c 2001-12-12 15:49:27
d 2001-12-12 15:49:30
d 2001-12-12 15:49:32
create or replace procedure test12 is
type times is table of number index by binary_integer;
type pays is table of varchar2(50) index by binary_integer;
t_times times;
t_pay pays;
cursor cursor1 is
select pay from table1
order by pay;
v_oldpay table1.pay%type;
v_newpay table1.pay%type;
v_times number;
i integer;
begin
v_times := 0;
v_oldpay := 'test';
i := 1;
Open cursor1;
loop
fetch cursor1 into v_newpay;
exit when cursor1%notfound;
if v_oldpay = 'test' then
v_oldpay := v_newpay;
v_times := v_times + 1;
elsif v_newpay = v_oldpay then
v_times := v_times + 1;
else
t_times(i) := v_times;
t_pay(i) := v_oldpay;
dbms_output.put_line('pay:'||t_pay(i)||'---times:'||t_times(i));
i := i + 1;
v_times := 1;
v_oldpay := v_newpay;
end if;
end loop;
t_times(i) := v_times;
t_pay(i) := v_oldpay;
dbms_output.put_line('pay:'||t_pay(i)||'---times:'||t_times(i));
close cursor1;
end test12;
/
SQL> set serveroutput on;
SQL> begin
2 dbms_output.enable;
3 end;
4 /