Re: Puzzled: CURSOR in Package

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 20 Nov 2001 09:56:37 -0800
Message-ID: <9te5gl026vf_at_drn.newsguy.com>


In article <kdwK7.164789$%94.29494383_at_news02.optonline.net>, "jane" says...
>
>Thanks, Conner , for your input.
>I understand but I still can't help thinking:
>The exact SAME benefits you indicated....
>can it not be achieved by simply put the WHOLE cursor
>declaration AND definition in the pkg spec as opposed just
>the cursor header in the pkg spec ?
>
>I mean I can just modify the SQL in the spec and recompile
>and nothing else is affected, right ?
>So this goes back to my original question. ie Putting the cursor
>in spec, that's good and well. But what I am wondering is why
>the SELECT in the body.
>
>jane

[Quoted] recompiling the spec invalidates all dependent code.

recompiling the body does not.

The spec should never change, the body can be reimplemented over and over and [Quoted] over without the cascading invalidations.

Its like why we just put the prototype of the functions/procedures of the [Quoted] pacakge in the spec and their implementation in the body. Just think of the [Quoted] packaged cursor as a subroutine -- the interface (inputs/outputs) goes into the [Quoted] spec, the implementation (the query) into the body. You can change the implementation without affecting (invalidating and forcing recompilation) of all dependent code.
>
>
>"Connor McDonald" <connor_mcdonald_at_yahoo.com> wrote in message news:
>> Its not about "hiding", its about modularity. You're publicising an
>> object (a cursor in this case), and (hopefully) you're publishing this
>> as an unchanging, guaranteed to be there definition. You're advertising
>> the fact that to (say) "get a list of employees", this is the cursor to
>> be used.
>>
>> You're protecting anyone that uses that cursor from the definition - it
>> may be a query from EMP, it might be a join, it might (in 9i) be a
>> PL/SQL routine that sends it results back via a pipelined clause...All
>> of which you can add/change/implement/etc without a single line of code
>> *outside* the package being needed.
>
>
>

--
Thomas Kyte (tkyte_at_us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Tue Nov 20 2001 - 18:56:37 CET

Original text of this message