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