Home » SQL & PL/SQL » SQL & PL/SQL » parameters of sub functions (10g ,R2, ALL)
parameters of sub functions [message #334313] Wed, 16 July 2008 03:13 Go to next message
shyam_pn
Messages: 7
Registered: August 2007
Junior Member
I am writing a package having 7 procedures and 3 functions.
I will call a main procedure from package with 5 (4 In and 1 OUT)
input parameters which inturn based on conditions will invoke other procedures/functions.
I use these parameters in almost all procedures.
So which of the method is better.
1) From the main procedure assign the parameter to a
global variable so that all sub- procedures/functions
can access.
2) Create signature/parameter list for all the sub-procedures/
functions and pass the input parameters.
Please advice.

[Updated on: Wed, 16 July 2008 03:14]

Report message to a moderator

Re: parameters of sub functions [message #334318 is a reply to message #334313] Wed, 16 July 2008 03:37 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Don't use global variables, use parameters.

Regards
Michel
Re: parameters of sub functions [message #334354 is a reply to message #334318] Wed, 16 July 2008 05:02 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
I would either
1) create a record type in the package body that would hold the parameters, pack the parameter into this at the start of the main procedure, and pass this record around as a single parameter.

2) If you can guarantee that the IN parameters will be passed, unaltered into the internal procedures and functions, then consider using package body globals.
They're an inferior solution, as they can be changed, which will affect all the code from there on, and many people consider them as bad as GOTOs.
Re: parameters of sub functions [message #334358 is a reply to message #334354] Wed, 16 July 2008 05:08 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
JRowbottom wrote on Wed, 16 July 2008 12:02
and many people consider them as bad as GOTOs.

I do in the case described; in my opinion global (package) variables should be used to define the state of the package, not because someone is too lazy to type out five parameters.
As for packing them into a single type, I would only do that if they are functionally related.
Again, I don't see a problem passing 5 parameters around.
Re: parameters of sub functions [message #334361 is a reply to message #334358] Wed, 16 July 2008 05:20 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
The problem with passing the same set of parameters around every single sub-unit is that it's a pain in the bottom. It makes the code much more verbose than it needs to be, and if you have to change the parameters later then it can take a significant time.

I'm of the opinion that it a piece of information needs to be available everywhere in a package, then it is (by definition) global.
Re: parameters of sub functions [message #334393 is a reply to message #334313] Wed, 16 July 2008 06:33 Go to previous messageGo to next message
shyam_pn
Messages: 7
Registered: August 2007
Junior Member
thanks for the reply .The parameters will not be modified for a session. I thought it may be an overhead in passing In/OUT variables around.
Re: parameters of sub functions [message #334395 is a reply to message #334393] Wed, 16 July 2008 06:34 Go to previous message
Frank
Messages: 7901
Registered: March 2000
Senior Member
Will they not be modified during a session or during a transaction?
Previous Topic: Mutating Trigger
Next Topic: Need Help in adding photo
Goto Forum:
  


Current Time: Fri Feb 14 15:28:33 CST 2025