Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Variable In List in PL/SQL
I'd like to produce a procedure (or more than one) that can parse a comma
delimited string and use it as a variable in-list in PL/SQL on 8i std
edition. Jonathan's neat use of objects is therefore out, but I was hoping
that the code below would work However it errors out with ora-00902 invalid
datatype for the select. I've now been staring at this for a couple of hours
and so cannot see my , no doubt daft, error. If anyone can cast an eye over
it, or suggest a better method that would be great. constraints are, has to
be in a package so it can return a ref cursor to an asp page and has to run
on 8i/9i std.
Create or replace package DWPack
as
Type DWPack_ListArray is table of varchar2(500);
Type rset is ref cursor;
Function ParseInList(i_list IN varchar2) return DWPack_ListArray;
Procedure ShowValuePercentage(i_valuelist in varchar2,i_percentageList in varchar2,io_rset in out rset);
end DWPack;
/
show errors;
create or replace package body DWPack
AS
Function ParseInList(i_list IN varchar2) return DWPack_ListArray
is
l_string long default i_list || ',';
l_data DWPack_ListArray := DWPack_ListArray();
n number;
begin
loop
exit when l_string is null;
n := instr( l_string, ',' );
l_data.extend;
l_data(l_data.count) := ltrim( rtrim( substr( l_string, 1, n-1 ) ) );
l_string := substr( l_string, n+1 );
end loop;
return l_data;
end ParseInList;
Procedure ShowValuePercentage(i_valueList in varchar2,i_percentageList in varchar2,io_rset in out rset)
is
l_results rset;
begin
open l_results for
select sum(t1.datavalue)/sum(t2.datavalue)*100 as val
from datavalue t1,datavalue t2 where t1.dataset_id in
(
select * from THE
(
select cast(ParseInList(i_valueList) as DWPack_ListArray) from dual
)
)
and t2.dataset_id in
(
select * from THE
(
select cast(ParseInList(i_percentageList) as DWPack_ListArray) from dual
)
)
and t1.datavalue_id=t2.datavalue_id;
io_rset:=l_results;
end ShowValuePercentage;
end DWPack;
/
-- Niall Litchfield Oracle DBA Audit Commission UKReceived on Wed Apr 16 2003 - 09:21:18 CDT