Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2004, 09:20 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass an Array as a Parameter to a Stored Procedure

Hi could someone help me on the best way to pass an array as a Parameter to a Stored procedure. This this case I am passing the string 'Bob,Sue' as a parameter and then I want 'Bob' and 'Sue' to end up as items in an IN list in a select statement. I tried parsing the string 'Bob,Sue' to create a varibable whose value is = 'Bob','Sue' and then reference that varible in the Select statement but that did not seem to work. I have copied that code below. If parsing a parameter string in this way is not the best method to handle this could someone please let me know what a better alternative would be. I am running Oracle version 9i running on NT.


CREATE OR REPLACE package body test_package as
procedure proto2 (
p_cust_seg_nbr in VARCHAR2,
p_start_bk_mo in number,
p_end_bk_mo in number,
o_customer_cursor out T_CURSOR)
IS
loopcount number;
posofcomma number;
tempstr varchar2(200);
origtempstr varchar2(200);
reconstr varchar2(200);
begin
posofcomma := INSTR(p_cust_seg_nbr,',');
origtempstr := p_cust_seg_nbr;
loopcount := 0;
if posofcomma > 0 then
while posofcomma > 0 loop
tempstr := substr(origtempstr,0,posofcomma-1);
origtempstr := substr(origtempstr,posofcomma+1);
posofcomma := instr(origtempstr,',');
if loopcount > 0 then
reconstr := reconstr||chr(39)||tempstr||chr(39)||',';
else
reconstr := chr(39)||tempstr||chr(39)||',';
end if;
loopcount := loopcount + 1;
end loop;
reconstr := reconstr||chr(39)||origtempstr||chr(39);
end if;
open o_customer_cursor for
select
reconstr as reconstr,
ename from emp
where ename IN (reconstr)
;
end;
end test_package;
/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass XML parameter to stored procedure BCullenward Classic ASP Databases 3 September 10th, 2008 02:07 PM
how to pass array to oracle stored procedure? zhao2007 Hibernate 1 March 21st, 2008 03:51 PM
pass null to the parameter in the stored procedure kokila BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 12th, 2007 03:02 AM
How to pass a parameter to a stored procedure? MaxGay2 VB.NET 2002/2003 Basics 1 November 8th, 2006 02:48 PM
Pass a List/Array to a Stored Procedure in SQL Ser sankar SQL Server 2000 4 November 11th, 2003 05:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.