如何向存储过程中,传递数组参数?
先看代码:
create or replace procedure procedure_my(id in number, ageArray in int[]) is
length number;
begin
length := ageArray.length;--这样写不对,那怎么求长度?
for i in 0..length loop
insert into Test(id ,age)
values(id ,ageArray [i]);--ageArray [i]这样写也不行吧?那怎么循环求值?
end loop;
commit;
end procedure_my;
数据库里边,是没有ageArray in int[]这样写法吧?那我若想传数组进来,怎么实现?为方便起见,数组为一维的就好了,数据库用得不熟,请大虾指教。
------解决方案--------------------1、将数组转换成逗号分隔字符串,在存储过程中解析
2、自己创建个类型,用于接收数组
CREATE TYPE array_table AS TABLE OF VARCHAR2 (50);
可以看下这个博客http://jackyrong.iteye.com/blog/1669733
------解决方案--------------------plsql里面的复杂数据类型有 数组类型
------解决方案--------------------String array[] = {"one", "two", "three","four"};
ArrayDescriptor des = ArrayDescriptor.createDescriptor("SchemaName.ARRAY_TABLE", con);
ARRAY array_to_pass = new ARRAY(des,con,array);
CallableStatement st = con.prepareCall("call SchemaName.proc1(?,?,?)");
st.setArray(1, array_to_pass);
st.registerOutParameter(2, Types.INTEGER); st.registerOutParameter(3,OracleTypes.ARRAY,"SchemaName.ARRAY_INT");
st.execute();
转自:http://jackyrong.iteye.com/blog/1669733