Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetch Into

Status
Not open for further replies.

getjbb

MIS
Jun 4, 2003
139
US
Using the command Fetch Into, is there a way to fetch selected fields into variables, when you do not know how may fields are in a select statement.
In the future I plan on using whatever script I create, so I am trying to get the Fetch Into statement as generic as possible. Could I do this using a Type Record:
TYPE rec1_t IS RECORD (field1 VARCHAR2(16), field2 NUMBER, field3 DATE);

But then again, the type record has a fixed number of fields. I will sometimes need more or less. I need something like field1.....fieldn, where n can be determined somehow.

For example my select could have field1, field2, field3 and
another time it could have field1, field2.

I plan on using the following loop:

OPEN myCursor;
LOOP
FETCH myCursor INTO ???????;
EXIT WHEN myCursor%NOTFOUND;
UTL_FILE.put_line(myFile,myFileLine);
END LOOP;
CLOSE myCursor;

Thanks.

getjbb
 
You might want to look into REF cursors. I think they would offer the flexibility you are looking for.
 
I took a look at method4 dynamic SQL and it seems to be very complicated. I guess I will read up on it some more and try to understand it. I did a search on it and cannot seem to find a clear real world use of it.

getjbb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top