--数组
DECLARE
TYPE test_plsql_varray IS VARRAY(100) OF VARCHAR2(20);
temp_varray1 test_PLSQL_VARRAY := test_plsql_varray('One','Two','Three');
temp_varray2 test_PLSQL_VARRAY := test_plsql_varray();
BEGIN
--dbms_output.put_line(temp_varray2.COUNT);
temp_varray2.EXTEND(4);
FOR i IN 1..temp_varray1.COUNT LOOP
temp_varray2(i) := temp_varray1(i);
END LOOP;
FOR i IN 1..temp_varray2.count LOOP
dbms_output.put_line('temp_varray2'||'('||i||'):['||temp_varray2(i)||']');
END LOOP;
END;
--索引表
declare
type tmp_tab is table of number index by binary_integer;
v_tmp tmp_tab;
begin
v_tmp(-1):=4;
v_tmp(2):=5;
v_tmp(3):=6;
v_tmp(6):=7;
for i in 1..v_tmp.count loop
if v_tmp.EXISTS(i)then
DBMS_OUTPUT.put_line(v_tmp(i));
v_tmp.delete(i);
end if;
end loop;
DBMS_OUTPUT.put_line('现有元素个数为:'||v_tmp.count);
end;
--嵌套表
DECLARE
TYPE t_nested_table IS TABLE OF NUMBER;
v_table t_nested_table;
BEGIN
v_table := t_nested_table(0,1,2,2,4);
v_table.DELETE(1);
DBMS_OUTPUT.put_line(v_table.COUNT());
FOR i IN 2..5 LOOP
IF v_table.EXISTS(i) THEN
DBMS_OUTPUT.put_line(v_table(i));
END IF;
END LOOP;
end;
--记录类型
--对象类型
CREATE or replace type coords as object (
x number,
y number
);
CREATE TABLE grid (num NUMBER, loc coords);
INSERT INTO grid
VALUES (10, coords(1, 2));
INSERT INTO grid
VALUES (20, coords(3, 4));
DECLARE
TYPE coordstab IS TABLE OF coords;
pairs coordstab;
BEGIN
SELECT loc
BULK COLLECT INTO pairs
FROM grid;
for i in 1..pairs.count loop
dbms_output.put_line('loc的值为:'||pairs(i).x||CHR(9)||pairs(i).y);
end loop;
END;