This discussion is archived
7 Replies Latest reply: Dec 14, 2012 8:53 PM by rp0428 RSS

question regarding packages

509401 Newbie
Currently Being Moderated
I had an interview, this question really amazed me. why we keep Package header and body separately in Oracle.
If anyone knows please let me know.

THanks in Advance
Ali
  • 1. Re: question regarding packages
    Frank Kulash Guru
    Currently Being Moderated
    Hi, Ali,

    If a package spec (or header) is changed, then all the objects that depend on it have to be re-compiled.

    By keeping the package body separate from the spec, dependent objects do not have to re-compiled when a change is made only to the body.
    For example, say you discover a bug in a package body: say you used a - sign where you should have used +. Since correcting the mistake does not affect what procedures are visible to users, or how they are called, then there's no reason why any dependent object should have to be re-compiled. Since the spec (which is all the other objects reference) is separate from the body, changes to the body do not affect the dependent objects.
  • 2. Re: question regarding packages
    Solomon Yakobson Guru
    Currently Being Moderated
    Several reasons. We can hide functionality. What we declare in package specification is public (don't confuse with user PUBLIC). Procedures/functions/cursors/variables... declared in package specification can be accessed by anyone who has execute privilege. Procedures/functions/cursors/variables... declared in package body but not in package specification are private and can't be fererenced outside the package even if user has execute on the package. Secondly, we can recompile package body without invalidating objects that are referencing the package. Possibly there are some other advantages.

    SY.
  • 3. Re: question regarding packages
    Hoek Guru
    Currently Being Moderated
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:7452431376537#7457640934445
    http://www.toadworld.com/KNOWLEDGE/KnowledgeXpertforOracle/tabid/648/TopicID/TPS3C1/Default.aspx
  • 4. Re: question regarding packages
    BluShadow Guru Moderator
    Currently Being Moderated
    Solomon Yakobson wrote:
    Several reasons. We can hide functionality. What we declare in package specification is public (don't confuse with user PUBLIC). Procedures/functions/cursors/variables... declared in package specification can be accessed by anyone who has execute privilege. Procedures/functions/cursors/variables... declared in package body but not in package specification are private and can't be fererenced outside the package even if user has execute on the package. Secondly, we can recompile package body without invalidating objects that are referencing the package. Possibly there are some other advantages.

    SY.
    Also, the package body can be wrapped so the code is not easily accessible to prying eyes, whilst the specification remains 'public' (as you say) so that people can interface with the package without having to concern themselves with how those procedure/functions etc. are actually implemented... making the package a 'black box'.
  • 5. Re: question regarding packages
    LPS Journeyer
    Currently Being Moderated
    The main thing is All the OOPS(Object oriented Programing System) concepts can be implemented in the Package.Data hiding,Data encapsulation and Function/procedure overloading.
  • 6. Re: question regarding packages
    509401 Newbie
    Currently Being Moderated
    Thanks everyone for your help.

    Regards
    Ali
  • 7. Re: question regarding packages
    rp0428 Guru
    Currently Being Moderated
    If your question is answered give HELPFUL or ANSWERED credit to those that helped you and make sure the question is marked ANSWERED.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points