question

Awad avatar image
Awad asked

Is it necessary to create a variable for every column while using cursor??

Hi. i want to create a function but there are many columns in that table.. so is it necessary to declare variable for every column to fetch data?? or is there any other way like CURSOR_NAME.COLUMN_NAME????? after that i had to wite the data into a file using UTL_FILE...
oracle
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JohnM avatar image
JohnM answered
There isn't any method like what you describe that I'm aware of. I'd like to expand @ruancra's answer in that you only need to declare a variable for a column if you need the value for that particular column. In other words, if you have 10 columns in a table and you only need 5 of them for your cursor, you would only need to create 5 variables, not 10. As a side note, usually using cursors is a last resort, at least in my opinion. Yes there are times & places in which it makes sense to use them, but you might be better off to try to get things done using a SET based method instead. Hope this helps!
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ruancra avatar image ruancra commented ·
That's correct, obviously variables are only required for the columns you need.
0 Likes 0 ·
ruancra avatar image
ruancra answered
Not exactly sure what you want to do, but yes you have to create a variable for each column in a cursor.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.