集合-Test1
- bulk collect into 批量插入,可用limit 限制插入行數
type
... is table of
DataType Index by binary_Integer 其中 index by binary_integer 在定義schema級 type 時沒有使用,而在session 級別的定義中必須使用
- extend 空間擴展,使用schema級別的 type 時需要使用extend 申請擴展空間,而回話級別是不需要的的。
- list1
multiset except
list2 從集合 list1中排除 list2並返回差集
declare
emp_type employee.employeename%type;
type emp_arr_type is table of varchar2(30) index by binary_integer;
emp_arr emp_arr_type;
type cur_type is ref cursor;
cur cur_type;
begin
open cur for select employeename from employee;
fetch cur bulk collect into emp_arr;
for i in 1..emp_arr.count
loop
dbms_output.put_line(emp_arr(i));
end loop;
end;
--------------輸出結果-----------
王紅
黎明
塗洪
王小兵
黃奮
李志強
李立
黃小紅
黃勇
王紅
黃志超
王加紅
章常勇
李紅
曾小勇
吳曉紅
-----------------------------------
declare
type emp_name_t is table of employee.employeename%type index by binary_integer;
emp_name emp_name_t;
l_row binary_integer;
begin
emp_name(2000):='zhangsan'; --回話級別的關聯數組直接賦值,無需單獨申請擴展空間
emp_name(-5):='李四';
emp_name(1):='22';
l_row:=emp_name.first;
while (l_row is not null)
loop
dbms_output.put_line(emp_name(l_row));
l_row:=emp_name.next(l_row);
end loop;
end;
-------------輸出結果--------
李四
22
zhangsan
-----------------------------
create type list_of_name_t is table of varchar2(100); --聲明一個schema級別的類型 list_of_name_t
declare
happyfamily list_of_name_t:=list_of_name_t(); --實例化對象
children list_of_name_t:=list_of_name_t();
parents list_of_name_t:=list_of_name_t();
begin
happyfamily.extend(4); --擴展4個空間
happyfamily(1):='eli';
happyfamily(2):='steven';
happyfamily(3):='chirs';
happyfamily(4):='veva';
children.extend; --使用之前先擴展空間(上面的例子不需要擴展空間是因爲類型是回話級別的)
children(1):='chirs';
children.extend;
children(2):='eli';
parents:=happyfamily multiset except children; --排除了集合children
for l_row in parents.first ..parents.last
loop
dbms_output.put_line(parents(l_row));
end loop;
end;
------------輸出結果----------
steven
veva
------------------------------