473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

FETCH arbitrary columns from a ref_cursor

The problem is as follows:
I have a stored proc. that returns a types.ref_cursor (where
types.ref_cursor is defined as 'ref cursor'):
PROCEDURE P(c OUT TYPES.ref_cursor);
The returned cursor has a bunch of columns, but I only need a few of them.
Anyway, with FETCH INTO I have to provide variables for every column. So I
have to do this:
var1 Type1;
var2 Type2;
...
FETCH c INTO var1, var2, ..., var20, ... var_n;
Where Type1, etc. ... are as specified in the documentation of P. (Since I
couldn't find a way to determine the record type of an arbitrary
ref_cursor.)
Is there a way to make this type of situation easier?
Some solutions came into my mind, such as:

1. I could declare a variable with the type c%ROWTYPE or something.
2. I could FETCH only the columns that I need, e.g.
FETCH c(col1, col5, col7) INTO var1, var5, var7;
3. I could somehow find a way for the procedure to return something other
than a ref_cursor which seems a nightmare to work with.

Unfortunately, I have found nothing like this either on the net or in the
Oracle documentation.

Any ideas?

Thx
Jul 19 '05 #1
1 8607
Agoston Bejo wrote:
The problem is as follows:
I have a stored proc. that returns a types.ref_cursor (where
types.ref_cursor is defined as 'ref cursor'):
PROCEDURE P(c OUT TYPES.ref_cursor);
The returned cursor has a bunch of columns, but I only need a few of them.
Anyway, with FETCH INTO I have to provide variables for every column. So I
have to do this:
var1 Type1;
var2 Type2;
...
FETCH c INTO var1, var2, ..., var20, ... var_n;
Where Type1, etc. ... are as specified in the documentation of P. (Since I
couldn't find a way to determine the record type of an arbitrary
ref_cursor.)
Is there a way to make this type of situation easier?
Some solutions came into my mind, such as:

1. I could declare a variable with the type c%ROWTYPE or something.
2. I could FETCH only the columns that I need, e.g.
FETCH c(col1, col5, col7) INTO var1, var5, var7;
3. I could somehow find a way for the procedure to return something other
than a ref_cursor which seems a nightmare to work with.

Unfortunately, I have found nothing like this either on the net or in the
Oracle documentation.

Any ideas?

Thx


The code has more problems than you may think:

select keyword
from v$reserved_words
where keyword like 'TY%';

Assuming Oralce 9i ... you don't say ... redefine as:

PROCDURE P (c OUT SYSREFCURSOR)

The solution to your problem can be found at:
http://www.psoug.org/reference/ref_cursors.html

--
Daniel A. Morgan
University of Washington
da******@x.washington.edu
(replace 'x' with 'u' to respond)

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: RR | last post by:
Hi, It appears that DB2 has an arbitrary restriction on the use of "fetch first N rows". I want to insert into a table from a large table query, but only insert the first N rows: insert...
4
by: db2admin | last post by:
hi, For the following SQL and plan ============================================================== SELECT Q1.PLCY_KY, Q1.PLCY_TRM_EFCTV_DT, Q1.ACNTG_BGN_DT, CASE WHEN ((Q1.PLCY_SRC_CD = '02')...
2
by: technocrat | last post by:
HOW CAN THIS BE DONE IN JAVA??? THIS IS POSITIONED UPDATE EXEC SQL DECLARE C1 CURSOR FOR SELECT * FROM EMPLOYEE FOR UPDATE OF JOB; EXEC SQL OPEN C1;
0
by: vinidimple | last post by:
Hi i have a serious problem while i was working in Excel.I want to fetch columns from an excel worksheet and i need to compare it with an sql querry fields,so i tried to open an excle...
0
by: Greg Collins [Microsoft MVP] | last post by:
I have written and posted the following articles which will prove useful to some: Display Lists in Columns Horizontally Using One Cell per Column...
1
by: angappan | last post by:
to fetch a list of rows and columns from xml and to store it in array and how to count the dynamic rows and columns ........ Help with code and explanations .... Iam very new to xml...
1
by: Agoston Bejo | last post by:
The problem is as follows: I have a stored proc. that returns a types.ref_cursor (where types.ref_cursor is defined as 'ref cursor'): PROCEDURE P(c OUT TYPES.ref_cursor); The returned cursor has...
0
by: padmaneha | last post by:
Hi Thanks for your response but the query which you gave in my previous post doesnt work. It displays the same cnt for movie reviews and videoreviews Let me explain you in detail As I...
3
Soniad
by: Soniad | last post by:
Hello, In stored procedure, i am using query that fetches 2 columns record but single row. i have used cursor to fetch single record. is there any way to fetch the record and put it in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.