代码如下:
--create by jenrry 20171028
-- 1.0 建立存放列的测试表
create table cux.cux_test_jenrry_1028
(
line_1 varchar2(240),
line_2 varchar2(240),
line_3 varchar2(240),
line_4 varchar2(240),
line_5 varchar2(240),
line_6 varchar2(240),
line_7 varchar2(240),
line_8 varchar2(240),
line_9 varchar2(240),
line_10 varchar2(240),
line_11 varchar2(240),
line_12 varchar2(240),
line_13 varchar2(240),
line_14 varchar2(240),
line_15 varchar2(240)
)
tablespace APPS_TS_TX_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 128
next 128
minextents 1
maxextents unlimited
pctincrease 0
);
create synonym apps.cux_test_jenrry_1028 for cux.cux_test_jenrry_1028;
--2.0 使用二维数组的一个例子
DECLARE
TYPE test_type IS RECORD(
line_1 cux_test_jenrry_1028.line_1%TYPE,
line_2 cux_test_jenrry_1028.line_2%TYPE,
line_3 cux_test_jenrry_1028.line_3%TYPE,
line_4 cux_test_jenrry_1028.line_4%TYPE,
line_5 cux_test_jenrry_1028.line_5%TYPE,
line_6 cux_test_jenrry_1028.line_6%TYPE,
line_7 cux_test_jenrry_1028.line_7%TYPE,
line_8 cux_test_jenrry_1028.line_8%TYPE,
line_9 cux_test_jenrry_1028.line_9%TYPE,
line_10 cux_test_jenrry_1028.line_10%TYPE,
line_11 cux_test_jenrry_1028.line_11%TYPE,
line_12 cux_test_jenrry_1028.line_12%TYPE,
line_13 cux_test_jenrry_1028.line_13%TYPE,
line_14 cux_test_jenrry_1028.line_14%TYPE,
line_15 cux_test_jenrry_1028.line_15%TYPE); --定义test记录类型
TYPE test_type_array IS TABLE OF test_type INDEX BY BINARY_INTEGER; --定义存放test记录的数组类型
test_rec test_type; --声明变量,类型:test记录类型
test_rec_array test_type_array; --声明变量,类型:存放test记录的数组类型
BEGIN
--数组赋值
test_rec.line_1 := '金额/列名';
test_rec.line_2 := '30';
test_rec_array(1) := test_rec;
test_rec.line_1 := '23';
test_rec.line_3 := '11';
test_rec_array(2) := test_rec;
--循环输出数组元素
FOR i IN 1 .. test_rec_array.count LOOP
DBMS_OUTPUT.PUT_LINE('i=' || i || ',line_1=' || test_rec_array(i)
.line_1 || ',line_2=' || test_rec_array(i).line_2);
END LOOP;
END;