【发布时间】:2017-02-21 23:55:34
【问题描述】:
我正在尝试使用光标从表(员工)中获取数据并保存到 asso。大批。但是,使用光标获取数据到记录更直接,并且将记录转换为关联数组(arr)很麻烦。下面的代码是我试图将数据提取到 assoc 数组并且需要改进的代码。还是光标以外的任何方法?谢谢。
DECLARE
TYPE AssoArray IS TABLE OF varchar2(30) INDEX BY varchar2(30);
arr AssoArray;
table_rec employee%rowtype;
CURSOR cur IS
SELECT * FROM employee;
BEGIN
OPEN cur;
LOOP
FETCH cur into table_rec;
EXIT WHEN cur%notfound;
-- how to improve the code in the section below,
arr('col1') := table_rec.col1;
arr('col2') := table_rec.col2;
arr('col3') := table_rec.col3;
...
arr('col50') := table_rec.col50;
-- end of section
-- do sth
END LOOP;
END;
【问题讨论】:
-
可以从记录中轻松获得各个值。关联数组可能带来哪些好处?
-
如果我们想从记录列列表中收集/计算值,使用 asso 会更方便。像 arr(col(i)) 这样的数组,其中 i 是索引。
-
直接对表格中的数据进行计算?
标签: arrays oracle plsql associative-array