Oracle之函数中使用游标

来源:互联网 发布:sunny crown 人工智能 编辑:程序博客网 时间:2024/06/05 17:10
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) thengoto label_end;end if;Result:=v_acc_nbr||','||Result;tempCount := tempCount +1;  end loop;  <<label_end>>  close v_cursor;  return(Result);  exception when others thenif(v_cursor%isopen) thenclose v_cursor;end if;    return '';end getcustprodinstaddr;

0 0
原创粉丝点击