close

 

有一個欄位裡面是填整數~~有的連續有的不連續~~把連續的整數歸在同一組

 

create table mc (id char(3));
insert into mc values('789');
select * from mc;
select substr(id,1,1), substr(id,2,1), substr(id,2,1) from mc;
select substr(id,2,1) from mc;
select substr(id,2,1) from mc;


set serveroutput on;
exec pro01;
create or replace procedure pro01
is
v_n1 char(1);
v_n2 char(1);
v_n3 char(1);
cursor c_1 is
select substr(id,1,1),substr(id,2,1),substr(id,3,1) from mc;
begin
open c_1;
loop
fetch c_1 into v_n1,v_n2,v_n3 ;
EXIT when c_1%NOTFOUND;
if (v_n1+1=v_n2 and v_n3-1=v_n2) then
dbms_output.put_line(v_n1||v_n2||v_n3||' continue');
else
dbms_output.put_line(v_n1||v_n2||v_n3||' non-continue');
end if;
end loop;
CLOSE c_1;
end;
/

 

output:

**********

 

已編譯 PROCEDURE pro01
匿名區塊已完成
123 continue
567 continue
125 non-continue
652 non-continue
789 continue

 

arrow
arrow
    全站熱搜

    to52016 發表在 痞客邦 留言(0) 人氣()