Unix Technical Forum

REF cursors vs. cursors

This is a discussion on REF cursors vs. cursors within the Oracle Database forums, part of the Database Server Software category; --> With cursors I could define a lot of my queries in the package specification. This is a convenient way ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 07:46 AM
Jake
 
Posts: n/a
Default REF cursors vs. cursors


With cursors I could define a lot of my queries in the package
specification. This is a convenient way to put queries in one place.
The parameterized cursor idea is nice too. Plus it helps in not
writing the same query many times throughout the code.

What if I would like to do a similar thing, but I need to use REF
CURSORS strictly for the ability to be able to pass the ref cursor to
a procedure. What's the preferred way of defining queries when using
REF CURSORS if I wanted to have a similar effect?

For example: Would it be feasible to define many VARCHAR2s that
represent queries in one package? Or is there a way to associate REF
CURSORS with a regular cursor that's defined in a package?

What would be the preferred way to do this?

thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 07:46 AM
DA Morgan
 
Posts: n/a
Default Re: REF cursors vs. cursors

Jake wrote:
> With cursors I could define a lot of my queries in the package
> specification. This is a convenient way to put queries in one place.
> The parameterized cursor idea is nice too. Plus it helps in not
> writing the same query many times throughout the code.
>
> What if I would like to do a similar thing, but I need to use REF
> CURSORS strictly for the ability to be able to pass the ref cursor to
> a procedure. What's the preferred way of defining queries when using
> REF CURSORS if I wanted to have a similar effect?
>
> For example: Would it be feasible to define many VARCHAR2s that
> represent queries in one package? Or is there a way to associate REF
> CURSORS with a regular cursor that's defined in a package?
>
> What would be the preferred way to do this?
>
> thanks.


Strongly or weakly typed?

If weakly typed just use sys_refcursor and be done with it.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 07:46 AM
William Robertson
 
Posts: n/a
Default Re: REF cursors vs. cursors

On Nov 7, 4:49 pm, Jake <jgarfi...@earthlink.net> wrote:
> With cursors I could define a lot of my queries in the package
> specification. This is a convenient way to put queries in one place.
> The parameterized cursor idea is nice too. Plus it helps in not
> writing the same query many times throughout the code.
>
> What if I would like to do a similar thing, but I need to use REF
> CURSORS strictly for the ability to be able to pass the ref cursor to
> a procedure. What's the preferred way of defining queries when using
> REF CURSORS if I wanted to have a similar effect?
>
> For example: Would it be feasible to define many VARCHAR2s that
> represent queries in one package? Or is there a way to associate REF
> CURSORS with a regular cursor that's defined in a package?
>
> What would be the preferred way to do this?
>
> thanks.


One approach might be to define packaged functions that returned ref
cursors.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-26-2008, 07:46 AM
Jake
 
Posts: n/a
Default Re: REF cursors vs. cursors

On Nov 7, 4:25 pm, DA Morgan <damor...@psoug.org> wrote:
> Jake wrote:
> > With cursors I could define a lot of my queries in the package
> > specification. This is a convenient way to put queries in one place.
> > The parameterized cursor idea is nice too. Plus it helps in not
> > writing the same query many times throughout the code.

>
> > What if I would like to do a similar thing, but I need to use REF
> > CURSORS strictly for the ability to be able to pass the ref cursor to
> > a procedure. What's the preferred way of defining queries when using
> > REF CURSORS if I wanted to have a similar effect?

>
> > For example: Would it be feasible to define many VARCHAR2s that
> > represent queries in one package? Or is there a way to associate REF
> > CURSORS with a regular cursor that's defined in a package?

>
> > What would be the preferred way to do this?

>
> > thanks.

>
> Strongly or weakly typed?
>
> If weakly typed just use sys_refcursor and be done with it.
> --
> Daniel A. Morgan
> University of Washington
> damor...@x.washington.edu (replace x with u to respond)
> Puget Sound Oracle Users Groupwww.psoug.org


well, i guess it's not so much which one to use. what I was meaning
to ask was, how to get the benefits of cursors (i.e. using
parameters, using a package to catalog your SQL), when you must use
cursor variables for the purposes of passing to procedures.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008, 07:46 AM
Jake
 
Posts: n/a
Default Re: REF cursors vs. cursors

On Nov 9, 3:35 am, William Robertson <williamr2...@googlemail.com>
wrote:
> On Nov 7, 4:49 pm, Jake <jgarfi...@earthlink.net> wrote:
>
>
>
> > With cursors I could define a lot of my queries in the package
> > specification. This is a convenient way to put queries in one place.
> > The parameterized cursor idea is nice too. Plus it helps in not
> > writing the same query many times throughout the code.

>
> > What if I would like to do a similar thing, but I need to use REF
> > CURSORS strictly for the ability to be able to pass the ref cursor to
> > a procedure. What's the preferred way of defining queries when using
> > REF CURSORS if I wanted to have a similar effect?

>
> > For example: Would it be feasible to define many VARCHAR2s that
> > represent queries in one package? Or is there a way to associate REF
> > CURSORS with a regular cursor that's defined in a package?

>
> > What would be the preferred way to do this?

>
> > thanks.

>
> One approach might be to define packaged functions that returned ref
> cursors.



thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com