Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how to create a stored procedure in oracle which accepts array of parameters

Can any one tell me if its possible to create a stored procedure in oracle which accept array as an input parameter and how ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...