Re: varargs in PL/SQL



Filipe David Borba Manana (fdmanana@xxxxxxx) 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.

.