oracle
create or replace function getYwzt(var_ywwid varchar2,var_ywbh varchar2)
return varchar2is
ywzt varchar2(2);
cursor cur_ywzt is
select rownum,inner_t.swclzt from(
select swclzt from zc_sqfq where ywwid=var_ywwid and ywbh like var_ywbh||'%' order by sfsqjs asc
) inner_t where rownum='1';
begin
FOR ywztList IN cur_ywzt LOOP
ywzt:=ywztList.swclzt;
EXIT WHEN cur_ywzt%NOTFOUND;
END LOOP;
RETURN ywzt;
end;
begin DECLARE ywzt varchar(2); declare done int default false; declare r decimal(65,0); DECLARE cur_ywzt cursor for select @rownum:=@rownum+1 rownum,inner_t.swclzt from (SELECT @rownum:=0) r,( select swclzt from zc_sqfq where ywwid=var_ywwid and ywbh like var_ywbh||'%' order by sfsqjs asc ) inner_t limit 1; -- 指定游标循环结束时的返回值 declare continue HANDLER for not found set done = true; -- 打开游标 open cur_ywzt; -- 开始循环游标里的数据 read_loop:loop -- 根据游标当前指向的一条数据 fetch cur_ywzt into r,ywzt; -- 判断游标的循环是否结束 if done then leave read_loop; -- 跳出游标循环 end if; -- 结束游标循环 end loop; -- 关闭游标 close cur_ywzt; RETURN ywzt; end
原文链接:https://www.f2er.com/oracle/208795.html