在PL/SQL内部可以用TABLE类型或者VARRAY类型传递数组类型变量

解决方案 »

  1.   

    先定义个数组
    type arr IS VARRAY OF VARCHAR2(255);t_description  arr;
      

  2.   

    数组定义:
    type arr Is VArray(2) Of VarChar2(8);
      

  3.   

    SQL> create or replace type myobjecttype as object (id number,description varcha
    r2(50));
      2  /Type created.Elapsed: 00:00:00.51
    SQL> create or replace type mytabletype as table of myobjecttype
      2  /Type created.Elapsed: 00:00:01.62
    SQL> commit;Commit complete.Elapsed: 00:00:00.20SQL> create or replace procedure sp_test (insertvalue mytabletype)
      2  is
      3    i number :=0;
      4  BEGIN
      5
      6    loop
      7      i :=i+1;
      8      INSERT INTO bb (id, name) VALUES (insertvalue(i).id, insertvalue(i).des
    cription);
      9      exit when i=insertvalue.count;
     10    end loop;
     11    COMMIT;
     12  END sp_test;
     13  /Procedure created.Elapsed: 00:00:00.51
    SQL> commit;Commit complete.Elapsed: 00:00:00.20SQL> select * from bb;no rows selectedElapsed: 00:00:00.20SQL> set serveroutput on
    SQL> declare
      2    v_tabletype mytabletype :=mytabletype();
      3    i number :=0;
      4    iname varchar2(50) :='asd';
      5  begin
      6    for i in 1..10 loop
      7      v_tabletype.extend;
      8      v_tabletype(v_tabletype.count) :=myobjecttype(i,iname);
      9    end loop;
     10    sp_test(v_tabletype);
     11    i:=0;
     12     select count(*) into i from bb ;
     13    dbms_output.put_line('table bb count is ' || i);
     14  end;
     15  /
    table bb count is 10PL/SQL procedure successfully completed.Elapsed: 00:00:00.30SQL> column name format a10
    SQL> select * from bb;        ID NAME
    ---------- ----------
             2 asd
             3 asd
             4 asd
             5 asd
             6 asd
             7 asd
             8 asd
             9 asd
            10 asd
             1 asd10 rows selected.Elapsed: 00:00:00.61
      

  4.   

    我必须在vc ado调用存储过程的。
    必须考虑把参数传递进去的。
    而不是直接调用pl/sql。