Unix Technical Forum

use an array as input parameter for procedure

This is a discussion on use an array as input parameter for procedure within the Oracle Miscellaneous forums, part of the Oracle Database category; --> I need to create a procedure that accept as input parameter an array of integer, how can realize it? ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:05 PM
Mariano
 
Posts: n/a
Default use an array as input parameter for procedure

I need to create a procedure that accept as input parameter an array
of integer, how can realize it?

PROCEDURE add_allPaz( ??? ) AS
BEGIN
// understand how many elements there are in array
END;

What should I use at place of ???

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:05 PM
Michel Cadot
 
Posts: n/a
Default Re: use an array as input parameter for procedure


"Mariano" <mariano.calandra@gmail.com> a écrit dans le message de news: 1182606785.877789.107950@m36g2000hse.googlegroups. com...
|I need to create a procedure that accept as input parameter an array
| of integer, how can realize it?
|
| PROCEDURE add_allPaz( ??? ) AS
| BEGIN
| // understand how many elements there are in array
| END;
|
| What should I use at place of ???
|

SQL> create or replace type my_array is table of number
2 /

Type created.

SQL> create or replace procedure p (p my_array)
2 is
3 begin
4 for i in p.first..p.last loop
5 dbms_output.put_line('p('||i||')='||p(i));
6 end loop;
7 end;
8 /

Procedure created.

SQL> exec p(my_array(1,4,7,19,5));
p(1)=1
p(2)=4
p(3)=7
p(4)=19
p(5)=5

PL/SQL procedure successfully completed.

Regards
Michel Cadot


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:05 PM
Mark D Powell
 
Posts: n/a
Default Re: use an array as input parameter for procedure

On Jun 23, 11:04 am, "Michel Cadot" <micadot{at}altern{dot}org> wrote:
> "Mariano" <mariano.calan...@gmail.com> a écrit dans le message de news:1182606785.877789.107...@m36g2000hse.googlegr oups.com...
> |I need to create a procedure that accept as input parameter an array
> | of integer, how can realize it?
> |
> | PROCEDURE add_allPaz( ??? ) AS
> | BEGIN
> | // understand how many elements there are in array
> | END;
> |
> | What should I use at place of ???
> |
>
> SQL> create or replace type my_array is table of number
> 2 /
>
> Type created.
>
> SQL> create or replace procedure p (p my_array)
> 2 is
> 3 begin
> 4 for i in p.first..p.last loop
> 5 dbms_output.put_line('p('||i||')='||p(i));
> 6 end loop;
> 7 end;
> 8 /
>
> Procedure created.
>
> SQL> exec p(my_array(1,4,7,19,5));
> p(1)=1
> p(2)=4
> p(3)=7
> p(4)=19
> p(5)=5
>
> PL/SQL procedure successfully completed.
>
> Regards
> Michel Cadot


To make passing an array between stored procedures or packaged routine
it is normal to declare the array type in a package header so that it
can just be referenced in the routines that will need to use the
structure.

Oracle provides several pre-defined array type definitions with the
dbms_utility package including

type uncl_array IS TABLE OF VARCHAR2(227) INDEX BY BINARY_INTEGER;

type name_array IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;

type dblink_array IS TABLE OF VARCHAR2(128) INDEX BY BINARY_INTEGER;

TYPE index_table_type IS TABLE OF BINARY_INTEGER INDEX BY
BINARY_INTEGER;

TYPE number_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;

Other types are provided in other supplied packages and where suitable
these predefined types should be used in your code to help increase
clarity of the code through the use of standard structures.

HTH -- Mark D Powell --

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com