Thursday 8 September 2011

How do I call proceduresfunctions without specifying the package name

Question:

Steven, I am using most of the built-in functions available in the STANDARD package. When I refer to those functions, I do not specify any package name.
Well, my applications have lots of functions and procedures. I want to call these procedures/functions without specifying the package name. Is it possible, as with the STANDARD package? Is there another means, as with the 'import packages' concept in Java? Or is there any way to create my functions or procedures in the STANDARD package itself?

Answer:

Suresh, PL/SQL was patterned after Ada, a programming language developed for the U.S. Department of Defense. In Ada, you can specify your default package, but with PL/SQL, those default packages (STANDARD and DBMS_STANDARD) have been specified and locked in. You cannot define your own default and thereby avoid providing the package name when calling your packaged programs. There is also no way to import your packages, as is done with Java.
Having said that, I honestly don't see these constraints as causing much difficulty. It doesn't seem to me to be too much of a trial to include the name of the package that owns the program. In fact, leaving off the name could lead to a general reduction in readability and maintainability of your code over time. I think it is worth the slight extra effort of prefixing our own package names at all times.

No comments:

Post a Comment