日期:2014-05-16  浏览次数:20606 次

oracle 数组实现

-一维数组:
--嵌套表
--尺寸没有限制。
--本质上是无序的
--VARRAY
--尺寸必须固定,所有的实例尺寸相同。
--在过程化语言中可以作为有序数组进行检索但在Oracle内部看成单个不能分割的单元。
--存储效率高。

--多维数组
--利用record 和record of


--建立测试
drop table t_test_1;
create table t_test_1(
pid??? number(10),
pname? varchar2(20),
birth? date,
score? number(3),
note?? varchar2(50)
);

--初始化,插入数据
--利用了nested table 来实现一维数组
--不需要制定上下限,下表可以不连续,需初始化
--
declare
? type type_test_pid is table of t_test_1.pid%type
? index by binary_integer;
? type type_test_pname is table of t_test_1.pname%type
? index by binary_integer;
? type type_test_birth is table of t_test_1.birth%type
? index by binary_integer;
? type type_test_score is table of t_test_1.score%type
? index by binary_integer;
? type type_test_note is table of t_test_1.note%type
? index by binary_integer;
?
? my_test_pid?? type_test_pid;
? my_test_panme type_test_pname;
? my_test_birth type_test_birth;
? my_test_score type_test_score;
? my_test_note? type_test_note;

? i number(10) := 0;

begin
? for i in 1 .. 10000
? loop
??? my_test_pid(i) := i;
??? my_test_panme(i) := 'names_' || to_char(i);
??? my_test_birth(i) :=? sysdate;
??? my_test_score(i) := to_number(nvl(substr(to_char(i), -2), to_char(i)));
??? my_test_note(i) := my_test_panme(i)|| ' score is ' ||
??????????????????? nvl