Skip to Main Content
  • Questions
  • Prefixing a packaged procedure call with the package name from inside said package ?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Douglas.

Asked: August 07, 2017 - 2:57 pm UTC

Last updated: August 08, 2017 - 11:43 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Within a single package two procedures call a function in the package. One prefixes with the package name and the other does not.
Is there any difference?

Thank you.

CREATE OR REPLACE PACKAGE BODY demo
AS
   FUNCTION f1 RETURN NUMBER IS
   BEGIN
      RETURN 1;
   END f1;
 
   PROCEDURE proc1 IS
      x   NUMBER;
   BEGIN
      x := f1;
   END proc1;
 
   PROCEDURE proc2 IS
      x   NUMBER;
   BEGIN
      x := demo.f1;
   END proc2;
END demo;


and Connor said...

Depends on the level "tightness" you want in the code base.

Let's assume you *just* have function f1 and proc2 in the package. (ie, no proc1).

If you have a standalone function called "f1", then if you were recreate the package *without* the internal function "f1", then proc2 will *still* compile happily, but is now referencing the standalone function f1.

That *might* be what you want...it might not be.

So you could argue that the package name prefix makes the code more robust, but in my experience, I've rarely seen it done for intra-package calls.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Uncertainty Eliminated

Douglas McAndrews, August 08, 2017 - 1:07 pm UTC

Very fast answer to a seemingly minor question that resolves my debate.
Ask TOM Rocks!
Connor McDonald
August 08, 2017 - 11:43 pm UTC

Glad we could help

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library