我有一个存储过程。我希望它有一个列名作为索引,而不是批量收集到
v_value_list
,例如:
v_values['DIST_TABLE.APPRVD'] = val1,
v_values['DIST_TABLE.TOT_CAP'] = val2,
v_values['DIST_TABLE.NEW_CAP'] = val3,
等等。我们可以使用批量收集到
values_table_type
(见下文)来实现这一点吗?
我的程序:
PROCEDURE pr_capacities_update(id_in IN NUMBER)
AS
v_value_list SYS.ODCINUMBERLIST;
v_values values_table_type;
TYPE values_table_type IS TABLE OF NUMBER INDEX BY VARCHAR2(100);
v_values values_table_type;
BEGIN
SELECT val
BULK COLLECT INTO v_value_list
FROM (
SELECT val
FROM DIST_TABLE
UNPIVOT (val FOR col IN (APPRVD, TOT_CAP, NEW_CAP, EXIST_CAP))
WHERE DIST_ID = id_in
);
END pr_capacities_update;
你不能,但一个简单的 FOR-LOOP 会处理它并提供相同的数组获取好处
PROCEDURE pr_capacities_update(id_in IN NUMBER)
AS
v_value_list SYS.ODCINUMBERLIST;
v_values values_table_type;
TYPE values_table_type IS TABLE OF NUMBER INDEX BY VARCHAR2(100);
v_values values_table_type;
BEGIN
for i in (
SELECT key, value
FROM ... )
loop
v_values(i.key) := i.value;
end loop;
END pr_capacities_update;