关于复合数据类型--PL/SQL表

PL/sql表和记录一样,都是用户自定义的数据结构。record类似于c语言中的结构(struct)而pl/sql表类似于c语言中的数组或集合,只是这个数据的元素可以是用户自定义的类型,也 包括record。
概括来讲,record可以存储一条记录,而pl/sql表可以存储多条record记录。
结构说明:
PL/SQL表只有两列,其中第一列为索引列为Integer类型索引列,9i后可以支持字符索引。第二列为用户自定义列,声明用户可用列类型.
 通过索引列中的索引值来操作PL/SQL表中对应的用户自定义列。类似于键值对。
 确保索引值的唯一性。如果索引值重复不会报错,会覆盖前面的值。
属性方法:
   count --返回pl/sql表的总行数;
   delect --删除pl/sql表的所有内容;
   delect(行数) --删除pl/sql表的指定的行;
   delct(开始行,结束行) --删除pl/sql表的多行;
   first --返回表的第一个INDEX;
   next(行数) --这个行数的下一条的INDEX;
   last --返回表的最后一个INDEX;

本文通过一个package包装可以用来返回PL/SQL表的存储过程和函数来掩饰pl/sql表的用法。
实例如下:
create or replace package page is---包头
  -- Public type declarations
  type TestTableType is table of t_test%rowtype index by binary_integer;
  -- Public function and procedure declarations
  par1 integer;
  par2 integer;
  i    integer;
  function mypagefunc(pagenum integer, pagecount integer)
    return TestTableType;
  procedure mypagepro(pagenum   integer,
                      pagecount integer,
                      rout      out TestTableType);
end page;
-----------------------------------------------------------------------------------------------------
create or replace package body page is--包体
  function mypagefunc(pagenum integer, pagecount integer)
    return TestTableType is
    Result TestTableType;
  begin
    par1 := pagenum * pagecount + 1;
    par2 := (pagenum - 1) * pagecount + 1;
    i    :=1;
    for r_out in (select t.t
                    from t_test t,
                         (select t from t_test where rownum < par1 order by t) t1
                   where t.t > (select max(t)
                                  from (select t
                                          from t_test
                                         where rownum < par2
                                         order by t))
                     and t.t = t1.t) loop
      Result(i).t := r_out.t;
      i := i + 1;
    end loop;
    return(Result);
  end;
  procedure mypagepro(pagenum   integer,
                      pagecount integer,
                      rout      out TestTableType) is
  begin
    par1 := pagenum * pagecount + 1;
    par2 := (pagenum - 1) * pagecount + 1;
    i    :=1;
    for r_out in (select t.t
                    from t_test t,
                         (select t from t_test where rownum < par1 order by t) t1
                   where t.t > (select max(t)
                                  from (select t
                                          from t_test
                                         where rownum < par2
                                         order by t))
                     and t.t = t1.t) loop
      rout(i).t := r_out.t;
      i := i + 1;
    end loop;
  end;
end page;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22333206/viewspace-612794/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22333206/viewspace-612794/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值