oracle 如何选择一个由VARCHAR2索引的数字表

tktrz96b  于 2023-08-03  发布在  Oracle
关注(0)|答案(1)|浏览(118)

我有一个存储过程。而不是批量收集到v_value_list,我希望它有一个列名作为索引,如:

v_values['DIST_TABLE.APPRVD'] = val1,
v_values['DIST_TABLE.TOT_CAP'] = val2,
v_values['DIST_TABLE.NEW_CAP'] = val3,

字符串
我们可以使用Bulk Collect Into the 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;

nukf8bse

nukf8bse1#

你不能,但是一个简单的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;

字符串

相关问题