I have been reading about packages, and may need to create one. I understand that the package body may not be necessary, but my question is, is the package SPEC always necessary? What if every function and procedure to be used in the package should be private to the body? What then do you put in the spec? Instructions also say to put as little as possible in the spec, as it is accessible to any other module. What would the syntax look like for creating a package with nothing in the spec portion?
Thanks for your help & enlightenment
Think about your question. If every method in the package were private, how would you every *use* the package?
I am just learning PL/SQL but I can tell you (because I've just been reading about it ) that while the body is not necessary, the specification is. They are actually stored as separtate objects in the data dictionary. So in answer to your quesiton, what if every procedure in the package is to be private to the package?.......perhaps just an empty specification, with no forward declarations?
My understanding is that packages are essentially logical groupings of operations to be made availabe without reusing code. Perhaps Im missing something, but if this is the case why would one want to fill a package solely with things that can't be seen from the outside? I would think EXECUTE priv. would serve that purpose.
Well maybe someone will clarify this!
Good luck to you,
Thank you both for your input.
My sole purpose for creating/using a package is that I have blocks of PL/SQL I want to re-use from within my procedure, calling them from within cursor for loops. You can't use a "goto" from a cursor loop or it closes the cursor after the first row.
I can either create these blocks as external functions/procedures that I call, but since nothing except my "main" processing block will use them, I thought I would just make them private to the package body. This package will be run by a job scheduler on a regular basis, and it accepts no input parameters, and has no output parameters (it write errors, etc. to another Oracle table).
If you have other suggestions on how to accomplish re-using code blocks from within cursor loops, I'd love to hear them.
Thanks for your time.
Those procedures can indeed be private, but this 'main' block that you are describing is not. I think I see the problem. You are thinking in terms of other languages where you have a main block and then procedures. Think object-oriented instead. The package is an object. It has methods. These methods can be externally exposed or internal only. You will be executing your one external method from somewhere else. This one external method then calls several internal methods.
The 'main' block in a package should be thought of as an instantiation method. It is run *once*, the first time that the package is loaded for a given session. It is used to initialize variables and the like, not to run code blocks. Put your main logic in a procedure. Declare that procedure in your header.
Hope this makes sense,
Yes, it helps. I think I'm starting to catch on.
Click Here to Expand Forum to Full Width