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
331 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ROBOFTP UNZIP 1 53
Redirecting an Outlook attachment to a specific folder? 3 58
Powershell File Sort 8 41
youtube blocking politics 4 59
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

830 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