Solved

How to get column names and/or column data from %ROWTYPE via column number in Oracle PL/SQL?

Posted on 2014-09-17
3
368 Views
Last Modified: 2014-11-14
Is something like this possible?
declare
  cursor c_pr is
    select * from a_table;
   r_pr c_pr%ROWTYPE;
begin
  open c_pr
  loop
    fetch c_pr into r_pr;
    exit when c_pr%NOTFOUND;
    for i in 1..r_pr.number_of_columns
    loop
       DBMS_OUPUT.put(r_pr.column(i)||chr(9));
    end loop;
       DBMS_OUTPUT.put_line('');
   end loop;
   close c_pr;
end

Open in new window

There may be other errors in the code - haven't really checked, but you should get my point. Can I extract column data and number of columns and eventually column names in a way something like above?

Thx!
IVer
0
Comment
Question by:IverErling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 500 total points
ID: 40327685
Short answer: the way you want to code it: NO
You'll have to use dynamic SQL with DBMS_SQL package, there should be numerous examples around the internet ;-)
If you need further help on that subject and/or own examples, just ask and I'll dig into my code snippets ;-)
0
 

Author Comment

by:IverErling
ID: 40327766
Ok. It's not that important to me at the moment. I just thought it would be nice to know if the info was held in the declared variable, and it just was a matter of knowing the syntax.
I have seen an example of something similar using dynamic SQL and it seemed unneccessarily complex. Strange really that not even the number of columns and the column numbers are known to the ROWTYPE variable!

THanks!

Brgds IVer
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 40327827
That's definetely a feature to PL/SQL that should be implemented in future versions ;-)
Accessing fields/columns within ROWTYPE variables through their corresponding names and/or indexes... That would be great...
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding a countdown to HTA 12 114
Do Wend Macro not working 22 72
what should i learn? javascript or typescript? 3 68
"lblTime is not declared" 3 65
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question