存储过程,游标,if,双游标,双循环

来源:互联网 发布:windows loader v2.5 编辑:程序博客网 时间:2024/06/03 18:22

题目:




drop table t;create table t(id varchar2(2),A varchar2(2),B varchar2(2))insert into t values('1','','B1');insert into t values('2','','B2');insert into t values('3','','B1');insert into t values('4','','B2');insert into t values('5','','B3');insert into t values('6','','B1');select * from t ;declare   t_id varchar(2);  t_b varchar(2);  t_a varchar(2);  t_id1 varchar(2);  t_a1 varchar(2);  t_b1 varchar(2);    cursor up is select count(B),B from t group by B order by b asc;  cursor up2 is select id,a,b from t;  begin open up;  loop     fetch up into t_a,t_b;      open up2;        loop           fetch up2 into t_id1,t_a1,t_b1;            if t_b1=t_b              then             update t set t.A=t_a where t.id=t_id1;            end if;        exit when up2%NOTFOUND;        end loop;        close up2;             exit when up%NOTFOUND;    end loop;    close up;  end;    select * from t;


原创粉丝点击