I’m trying to write a sql*plus script that runs a single arbitrary procedure. The tricky part is that I want to be able to run the procedure regardless of how many parameters that procedure takes.
To figure out the correct number of arguments for the procedure, I’m doing the following:
SELECT COUNT(*) INTO v_in
FROM all_arguments
WHERE LOWER(owner) = LOWER(v_schema)
AND LOWER(package_name) = LOWER(v_package)
AND LOWER(object_name) = LOWER(v_proc)
AND in_out = 'IN';
When it comes time to build the execute-immediate string, I wanted to use a loop of some sort to do that. The parameters are all being pass in are just numbered, &1 through &n.
FOR i IN 1..v_in
LOOP
v_block := v_block || '''' || &i || '''';
IF i != v_in THEN
v_block := v_block || ',';
END IF;
END LOOP;
This doesn’t work however. It sees &i and of course thinks that it is a parameter named i, and since the scheduling application (Appworx… ugh) isn’t running a define i=something, this fails miserably.
Is there any way to do indirection in this, such that I can iterate through however many happens to be correct for the given procedure?
You can trick this with new_value and defaulting SQL*Plus parameters.
Create a script like that, say for example test.sql:
Now call with
@test 3 4Output:
Or call with
@test 1 2 3Output:
Now you need to extend to this to the maximum expected number of your parameters.
(Note you have to be logged on to make this work, otherwise the
select from dualwill fail silently.)