Robert Baillie has posted a nice article reminding us about the use of “named notation” for program parameters, which triggered my memory about a problem I have had to deal with. I’m sure that some of you have encountered a situation when you needed to add an additional IN parameter to a program and use this new parameter in only one call. The other calls to this program did not need to pass any value to the new parameter. But if you added the new parameter to the program, you would break all the other calls. At the same time, you did not have the luxury to modify all the other calls. You were faced with a dilemma. Here is the solution, consider:
scott@eddev> create or replace procedure test_proc
2 (param1_in in number, param2_out out varchar2)
3 as
4 begin
5 param2_out := 'done';
6 end;
7 /
Procedure created.
Normally, I do not create procedures. I always use packages. But I’ll make an exception here for the sake of proving a point. Let’s test calling the procedure:
scott@eddev> declare
2 value_out varchar2(20);
3 begin
4 test_proc (1, value_out);
5 dbms_output.put_line(value_out);
6 end;
7 /
done
PL/SQL procedure successfully completed.
Now, let’s add another IN parameter, param2_in:
scott@eddev> create or replace procedure test_proc
2 (param1_in in number, param2_in in number, param2_out out varchar2)
3 as
4 begin
5 param2_out := 'done';
6 end;
7 /
Procedure created.
If you now call the procedure again exactly like we did above, i.e. test_proc (1, value_out); you get the following error:
ERROR at line 4:
ORA-06550: line 4, column 5:
PLS-00306: wrong number or types of arguments in call to 'TEST_PROC'
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
Unless you change the call to something like this test_proc (1, 2, value_out);, you will always get an error. But assuming that you cannot modify the call, you can still overcome this problem by doing two things:
- Put the new IN parameter at the end of the parameters list
- Default it to NULL
So, the procedure declaration would be:
test_proc (
param1_in in number,
param2_out out varchar2,
param2_in in number default null)
Problem solved, you can now successfully call the procedure like this
test_proc (1, value_out);
or like this
test_proc (1, value_out, 2);
without getting any errors.
Possibly related:
- Two Quick and Simple Tips That Will Help You Write Better PL/SQL
- SYS_CONTEXT in Oracle
- Random string generator
- Comments Do Make a Difference
- Go ahead, turn your FIPS flagging on
Tagged pl/sql | Post a Comment


















Don’t need to move it to the end. You can specify your arguments in your procedure calls. That is a good habit to get into anyway.
scott@Robert> create or replace procedure test_proc
2 (param1\_in in number, param2\_in in number := 1, param2\_out out varchar2)
3 as
4 begin
5 param2\_out := ‘done’;
6 end;
7 /
scott@Robert> declare
2 value\_out varchar2(20);
3 begin
4 test\_proc (param1\_in => 1, param2\_out => value\_out);
5 dbms\_output.put_line(value\_out);
6 end;
7 /
done
“Normally, I do not create procedures. I always use packages.”
What do you mean by that? You create packages with stored procedures inside them?
August 10th, 2005, at 1:52 pm #_Don’t need to move it to the end. You can specify your arguments in your procedure calls_
What if you cannot or do not want to change how you call the procedure. At work, I have one procedure that is called by 20 others. I do not have access to the other 20 calling procedures and they do not use named notation in their calls. Now I want to add a new IN parameter to the called procedure. What shall I do? That’s what I’m trying to solve here.
_What do you mean by that?_
Sorry, I was not clear. I meant I always avoid standalone procedures and functions. I always create my procedures and functions inside packages. [Here](http://www.oracle.com/technology/oramag/oracle/05-may/o35plsql.html) is a good article by Steven Feuerstein about this subject.
August 10th, 2005, at 2:16 pm #Sorry Eddie,
The permalink address for that entry has changed (so much for the perma part of that name!).
It’s now: http://robertbaillie.blogspot.com/2005/08/named-notation-parameters-in-easy-to.html
August 10th, 2005, at 10:53 pm #Rob, the link should be fixed now.
August 10th, 2005, at 11:22 pm #Great Feuerstein link, thanks!
August 11th, 2005, at 9:38 am #