my %dispatch = ( # Key = name of proc # Value = array of arguments to pass "PAR_REPORTS_POS.SUN_PRC_AT_I_POSM1D007" => [ \$retcode, \$retmsg ], "PAR_REPORTS_POS.SUN_PRC_AT_I_POSM1W001" => [ \$retcode, \$retmsg, \$finRepId, \$showPendingPolicies ], # and so on ); # Later... my $args = $dispatch{$procName}; my $procedure = "BEGIN $procName( " . join(',', (('?') x @$args)) # that makes a comma-separated list of '?'s, # the same number as there are elements in $args . "); END;"; my $function = $dbh->prepare($procedure); my $argc = 1; for my $arg (@$args) { $function->bind_param($argc++, $arg, SQL_VARCHAR); } $function->execute; #### my ($procedure, $function); DISPATCH: { if ($procName eq "PAR_REPORTS_POS.SUN_PRC_AT_I_POSM1D007") { $function = $dbh->prepare("BEGIN $procName(?, ?); END;"); $function->bind_param(1, \$retcode, 100); #? 100? $function->bind_param(2, \$retmsg, 100); last DISPATCH; } if ($procName eq "PAR_REPORTS_POS.SUN_PRC_AT_I_POSM1W001") ( $function = $dbh->prepare("BEGIN $procName(?, ?, ?, ?); END;"); $function->bind_param(1, \$retcode, 100); #? 100? $function->bind_param(2, \$retmsg, 100); $function->bind_param(3, \$finRepId, SQL_VARCHAR); $function->bind_param(4, \$showPendingPolicies, SQL_VARCHAR); last DISPATCH; } # and so on... } #close block labelled DISPATCH; $function->execute;