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: varargs in PL/SQL

Re: varargs in PL/SQL

From: Malcolm Dew-Jones <yf110_at_vtn1.victoria.tc.ca>
Date: 24 Feb 2007 13:38:41 -0700
Message-ID: <45e0b061$1@news.victoria.tc.ca>


Filipe David Borba Manana (fdmanana_at_cern.ch) wrote:
: Is there any way to create a function/procedure in PL/SQL with a
: variable arguments lists?

: I want to create a procedure which may be called with 1, 2, 3... or any
: number of parameters, say, something like the printf family of functions
: in C.

: Anyway to do it?

No, but...

you can define a procedure that takes a large number of parameters and defaults them all to NULL.

create procedure print_lines (

	p1 varchar2 default := NULL ,
	p2 varchar2 default := NULL ,
	...
	p99 varchar2 default := NULL )
	...
begin
	if p1 is not null then dbms_output.print_line(p1); end if;
	if p2 is not null then dbms_output.print_line(p2); end if;
	...
	if p99 is not null then dbms_output.print_line(p99); end if;
end

which can then be called like

	print_lines(
		'This is the first line',
		' ',
		'This is actuially the third line.'
		'The end.' );

it isn't elegent but it works.

OR

put the varying parameters in an array and pass the array as the parameter. Received on Sat Feb 24 2007 - 14:38:41 CST

Original text of this message

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