zoukankan      html  css  js  c++  java
  • 使用 oracle pipelined 返回一个结果集;

    1.使用

     1 create or replace package refcursor_pkg is
     2 
     3   -- Author  : mr.yang
     4   -- Created : 5/14/2017 5:13:42 PM
     5   -- Purpose : 
     6   type refcur_t is ref cursor return sys_product%rowtype;
     7   type refcur_t1 is ref cursor /*return sys_product%rowtype*/
     8   ;
     9   type refcur_t2 is ref cursor return base_member%rowtype;
    10 
    11   type outrec_typ is record(
    12     v_pid   integer,
    13     v_pcode varchar(4000),
    14     v_pname varchar(4000));
    15 
    16   type outrecset is table of outrec_typ;
    17   function f_trans(p refcur_t) return outrecset
    18     pipelined;
    19   function f_trans1(p refcur_t1) return outrecset
    20     pipelined;
    21   function f_trans1(sp refcur_t1, bm refcur_t2) return outrecset
    22     pipelined;
    23 
    24 end refcursor_pkg;


    2.body

     1 create or replace package body refcursor_pkg is
     2   function f_trans(p refcur_t) return outrecset
     3     pipelined as
     4     out_rec outrec_typ;
     5     in_rec  p%rowtype;
     6   
     7   begin
     8   
     9     loop
    10       fetch p
    11         into in_rec;
    12       exit when p%notfound;
    13       out_rec.v_pid   := in_rec.productid;
    14       out_rec.v_pcode := in_rec.productcode;
    15       out_rec.v_pname := in_rec.productname;
    16     
    17       pipe row(out_rec);
    18     end loop;
    19     close p;
    20     return;
    21   Exception
    22     when others then
    23       dbms_output.put_line(sqlcode || sqlerrm);
    24   end f_trans;
    25 
    26   function f_trans1(p refcur_t1) return outrecset
    27     pipelined as
    28     out_rec outrec_typ;
    29     in_rec  sys_product%rowtype;
    30   begin
    31     loop
    32       fetch p
    33         into in_rec;
    34       exit when p%notfound;
    35       out_rec.v_pid   := in_rec.productid;
    36       out_rec.v_pcode := in_rec.productcode;
    37       out_rec.v_pname := in_rec.productname;
    38     
    39       pipe row(out_rec);
    40     end loop;
    41     close p;
    42     return;
    43   Exception
    44     when others then
    45       dbms_output.put_line(sqlcode || sqlerrm);
    46     
    47   end f_trans1;
    48   ---------------------------------------------------------
    49   function f_trans1(sp refcur_t1, bm refcur_t2) return outrecset
    50     pipelined as
    51   
    52     out_rec   outrec_typ;
    53     in_rec    sys_product%rowtype;
    54     in_rec_bm bm%rowtype;
    55   begin
    56   
    57   
    58     loop
    59       fetch sp
    60         into in_rec;
    61       exit when sp%notfound;
    62       /*   out_rec.v_pid   := in_rec.productid;
    63          out_rec.v_pcode := in_rec.productcode;
    64          out_rec.v_pname := in_rec.productname;
    65          pipe row(out_rec);
    66       out_rec.v_pid   := in_rec_bm.id;
    67          out_rec.v_pcode := in_rec_bm.cnfullname;
    68          out_rec.v_pname := in_rec_bm.pinyin;
    69           pipe row(out_rec);*/
    70     
    71     end loop;
    72     close sp;
    73   
    74     loop
    75       fetch bm
    76         into in_rec_bm;
    77       exit when bm%notfound;
    78       out_rec.v_pid   := in_rec_bm.id;
    79       out_rec.v_pcode := in_rec_bm.cnfullname;
    80       out_rec.v_pname := in_rec_bm.pinyin;
    81       pipe row(out_rec);
    82       
    83       out_rec.v_pid   := in_rec.productid;
    84       out_rec.v_pcode := in_rec.productcode;
    85       out_rec.v_pname := in_rec.productname;
    86       pipe row(out_rec);   
    87     end loop;
    88     close bm;
    89   
    90     return;
    91   Exception
    92     when others then
    93       dbms_output.put_line(sqlcode || sqlerrm);
    94     
    95   end f_trans1;
    96 
    97 end refcursor_pkg;
    View Code

    3.结果:

  • 相关阅读:
    (转) asp.net中使用ajax中的三种方式
    转ASP.NET 防盗链的实现[HttpHandler]
    (转)ADO.net,Linq to SQL和Entity Framework性能实测分析
    (转) JS日历控件集合附效果图、源代码
    正则表达式收集
    Asp.net 打开页面错误 (无法显示 XML 页。使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。)
    SQL优化原则
    转载 25个优秀的 ASP.NET MVC教程及文章
    SQL 时间格式格式化
    任务失败,原因是未找到“LC.exe”,或未安装正确的 Microsoft Windows SDK。
  • 原文地址:https://www.cnblogs.com/linbo3168/p/9037461.html
Copyright © 2011-2022 走看看