Can any one tell me if its possible to create a stored procedure in oracle which accept array as an input parameter and how ?
views:
5397answers:
2
+1
A:
If I'm not wrong, there's a native type called TABLE that basically is an array. But last time I used it was 2001 so maybe there are most powerful types nowadays.
Lluis Martinez
2009-05-06 21:51:53
+4
A:
Yes. Oracle calls them collections and there's a variety of collections you can use.
A simple array example using a VARRAY.
DECLARE
TYPE Str_Array IS VARRAY(4) OF VARCHAR2(50);
v_array Str_Array;
PROCEDURE PROCESS_ARRAY(v_str_array Str_Array)
AS
BEGIN
FOR i IN v_str_array.first .. v_str_array.last LOOP
DBMS_OUTPUT.PUT_LINE('Hello '||v_str_array(i));
END LOOP;
END;
BEGIN
v_array := Str_Array('John','Paul','Ringo','George');
PROCESS_ARRAY(v_array);
-- can also pass unbound Str_Array
PROCESS_ARRAY(Str_Array('John','Paul','Ringo','George'));
END;
David
2009-05-06 22:19:06
very excellent. I added a second example showing Str_Array(...) as the parameter.
Mark Harrison
2009-07-03 09:19:18