Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Input array string

Re: Input array string

From: Mark C. Stock <mcstockX_at_Xenquery>
Date: Tue, 27 Jan 2004 20:48:46 -0500
Message-ID: <e8ydnSBwIsq5iIrdRVn-ug@comcast.com>


well, not doing .nit stuff currently, can't tell you how it stuffs arrays into oracle procs -- but i'd really, really be surprised if it can't be done, as it was such a major issue with VB/RDO/ADO and solutions were available from MS and Oracle and a third party vendor -- which may have been DataDirect under a prior name; check out 'Arrays of parameters (bulk inserts/updates)' on
http://www.datadirect-technologies.com/products/dotnet/docs/dotnet-interop.asp it looks like it might be related to your needs

meanwhile, on the generalization side -- you just need to apply a little more design, i.e:

have the 'array' parameter start (and optionally end) with the separator character, and create a reusable oracle procedure that translates any 'array' parameter into the PL/SQL table needed by the proc doing the actual work

ie:



CREATE OR REPLACE procedure populate_tbl(

      ip_tbl in out vc4000tbl
    , ip_arr in varchar2 )
is
  offset number default 2;
  dlen number default length(ip_arr);   slen number;
  sep varchar2(1) := substr(ip_arr,1,1); begin
  ip_tbl.delete;
  while offset < dlen
  loop

     slen := instr(ip_arr,sep,offset);
     if slen = 0
     then
        slen := dlen+1;
     end if;

  ip_tbl.extend;
  ip_tbl(ip_tbl.count) := substr(ip_arr,offset,slen-offset);

     offset := slen+1;
  end loop;
end populate_tbl;
/



which then gets reused as needed:

procedure list_emps ( ip_depts in varchar2 ) is

  for r1 in (

     select empno, ename, deptno
   from emp
   where deptno in (

      select column_value
    from table(cast(tbl_deptno as vc4000tbl))     )
   order by deptno, empno
   )
  loop

     dbms_output.put_line(
     r1.deptno
   || ': '
   || r1.empno

   || ' -- '
   || r1.ename);
  end loop;
end list_emps;

SQL> exec list_emps('|10|20|30')

is it the best tool in all cases? nothing ever is. but it's a good tool to have in the drawer.

Received on Tue Jan 27 2004 - 19:48:46 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US