DISQUS

Eddie Awad’s Blog: Two Quick and Simple Tips That Will Help You Write Better PL/SQL

  • Brian Tkatch · 1 year ago
    "So, in general, as a best practice, always use named notation when invoking PL/SQL procedures and functions. To avoid breaking existing code, add new parameters with DEFAULT values to the end of the parameter list of existing procedures or functions."

    Wouldn't overloading the routine accomplish the same goal?
  • Eddie Awad · 1 year ago
    Hi Brian,

    using named notation is the best approach to invoking a subprogram, whether you overload or not. But, yes, if the goal is not to break existing code when adding new parameters, overloading the routine can accomplish this goal. Thanks for point this out.
  • Cristian Cudizio · 1 year ago
    Eddie, what do you think about the fact that in function calls named notation (to 10g, i don't know 11g) is not supported?
    I think that overload may be a good solution but it depends of what do you have to do with the new parameter.

    Cheers,
    Cristian
  • Eddie Awad · 1 year ago
    Hi Cristian,

    I believe that named notation is not supported in 10g (and earlier releases) only when you call a function inside a SELECT statement. However, in 11g, this has been fixed.

    Check out the link titled "11g New Features: Efficient PL/SQL Coding" in the post above. There is more information about this towards the end of the page.
  • Chris Muir · 1 year ago
    Hi Eddie

    Not sure I agree with you on this one in all cases and you hint that you nearly always use named notation, implying there are cases when you use positional notation. In particular I'll point out 2 cases where positional notation is typically used:

    1) Oracle has a number of predefined functions that we rarely ever use named parameter notation for. eg upper, lower etc.

    2) If you have a simple function with 1 parameter such as get_name(id IN person.id%TYPE), the code is self explanatory without the named notation extension and I think overkill for simple cases:

    DECLARE
    person_id person.id%TYPE := 5;
    name person.name%TYPE;
    BEGIN
    name := somepackage.get_name(person_id);
    END;

    Besides these trivial cases, I agree with the rest of your points. Now you need a post on writing "meaningful parameter names" ;)

    Regards,

    CM.
  • Eddie Awad · 1 year ago
    Valid points Chris, especially on writing meaningful parameter names, not to mention meaningful variables names, procedure names, function names, package names....

    Maybe I should not have put "in general", "best practice" and "always" in the same sentence :)
  • Paweł Barut · 1 year ago
    Hi,

    I fully agree with Chris. I really like name notation and I use it often, but not always.
    When I use standard Oracle build in functions or for well established API (mine, 3rd party, or specific to project) with limited number of parameters (usually up to 3 or 4) I rather use positional notation.
    And of course within SQL statements, where named parameters are not allowed (hope I will work on 11g soon)

    Regards,
    Pawel
  • Eddie Awad · 1 year ago
    By the way, as you've noticed from the example code above, I also like to add _in to the end of IN parameter names, _out for OUT parameters and _inout for IN OUT. This makes the named notation even more readable.