我有一个plsql过程,它需要一个数据数组并更新一堆记录,我可以使用for循环执行此操作。我真的可以使用一些帮助,找出没有循环做到这一点。使用“IN”而不是“FOR”循环与集合
包装规格和身体:
create or replace PACKAGE ARRAY_EXAMPLE AS
type arrtype is table of test_table.name%TYPE index by pls_integer;
PROCEDURE PROCESS_ARRAY(stringArrayIn IN arrtype
, p_city varchar2
, p_phone number);
END;
/
create or replace PACKAGE BODY ARRAY_EXAMPLE AS
PROCEDURE PROCESS_ARRAY(stringArrayIn IN arrtype
, p_city varchar2
, p_phone number) IS
BEGIN
FOR i IN 1..stringArrayIn.Count
LOOP
update test_table t
set t.city = p_city
where t.name = stringArrayIn(i)
and t.phone = p_phone;
END LOOP;
END;
END;
/
我想拥有什么:
create or replace PACKAGE BODY ARRAY_EXAMPLE AS
PROCEDURE PROCESS_ARRAY(stringArrayIn IN arrtype
, p_city varchar2
, p_phone number) IS
BEGIN
update test_table t
set t.city = p_city
where t.phone = p_phone
and t.name in (stringArrayIn);
END;
END;
我得到的错误,当我尝试上述情况,请大家帮忙。非常感谢你提前。
感谢您的回复,但我无法获得索引,如果我在包体外声明,是否有解决方法? – Radan
您似乎将关联数组用作普通数组(即从1到n而非稀疏数组索引)。你为什么需要这个索引? – MT0
我决定采用这种方法,使用这个http://www.oracle.com/technetwork/articles/fuecks-sps-095636.html – Radan