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 -> Variable In List in PL/SQL

Variable In List in PL/SQL

From: Niall Litchfield <n-litchfield_at_audit-commission.gov.uk>
Date: Wed, 16 Apr 2003 15:21:18 +0100
Message-ID: <3e9d66e1$0$29717$ed9e5944@reading.news.pipex.net>


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 UK
Received on Wed Apr 16 2003 - 09:21:18 CDT

Original text of this message

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