Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1350383
  • 博文数量: 205
  • 博客积分: 6732
  • 博客等级: 准将
  • 技术积分: 2835
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-04 17:59
文章分类

全部博文(205)

文章存档

2016年(1)

2015年(10)

2014年(1)

2013年(39)

2012年(23)

2011年(27)

2010年(21)

2009年(55)

2008年(28)

我的朋友

分类: Oracle

2009-08-13 09:30:29

当一个例子使用:

create or replace function getcustprodinstaddr(in_CustId in number,in_area_code in number) return varchar2 is
  Result varchar2(4000);
  v_acc_nbr varchar2(400);
  tempCount number:=1;
  type ref_cursor is ref cursor;
  v_cursor ref_cursor;
begin
  Result:='';
  open v_cursor for
  'select install_addr from tb_prd_prd_inst_'||to_char(in_area_code)||
  ' where PRD_INST_STAS_ID not in(''1003'',''1101'',''1401'',''1102'') and own_cust_id='||to_char(in_CustId)
  ||' order by install_date desc';

  loop
    fetch v_cursor into v_acc_nbr;
        exit when v_cursor%notfound;
        if(tempCount>8) then
               goto label_end;
        end if;
        Result:=v_acc_nbr||','||Result;
        tempCount := tempCount +1;

  end loop;

  <<label_end>>
  close v_cursor;
  return(Result);
  exception when others then
      if(v_cursor%isopen) then
        close v_cursor;
      end if;
            return '';
end getcustprodinstaddr;

阅读(601) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~