Working with REF CURSOR in PL/SQL - Working with RECORD and REF CURSOR (
Page 2 of 4 )
Until now, we have been working either with %TYPE or %ROWTYPE. This means we are working with either one value or one complete record. How do we create our own data type, with our own specified number of values to hold? This is where TYPE and RECORD come in. Let us consider the following example:
declare
type r_cursor is REF CURSOR;
c_emp r_cursor;
type rec_emp is record
(
name varchar2(20),
sal number(6)
);
er rec_emp;
begin
open c_emp for select ename,sal from emp;
loop
fetch c_emp into er;
exit when c_emp%notfound;
dbms_output.put_line(er.name || ' - ' || er.sal);
end loop;
close c_emp;
end;
The most confusing aspect from the above program is the following:
type rec_emp is record
(
name varchar2(20),
sal number(6)
);
The above defines a new data type named "rec_emp" (just like %ROWTYPE with limited specified fields) which can hold two fields, namely "name" and "sal."
er rec_emp;
The above statement declares a variable "er" based on the datatype "rec_emp." This means that "er" internally contains the fields "name" and "job."
fetch c_emp into er;
The above statement pulls out a row of information (in this case "ename" and "sal") and places the same into the fields "name" and "sal" of the variable "er." Finally, I display both of those values using the following statement:
dbms_output.put_line(er.name || ' - ' || er.sal);
| | Discuss Working with REF CURSOR in PL/SQL | | | | | | | This is a simple introduction to REF CURSOR in PL/SQL. Hope you will enjoy it. If... | | | | | | dear sir,
this article is very use full for the beginner like me.
Thanks a... | | | | | | It is very good article for the starters in PL/SQL | | | | | | thanks!
this was a great article for me and gave me new insights. | | | | | | I would like to know how to handle data from a ref cursor to a record type when i... | | | | | | I liked they way,all your topics are put in.This one was also very easy to... | | | | | | This is really to good explanation with examples. I was able to understand it in a... | | | | | | very good one | | | | | | great way of explaining the concept | | | | | | Its really a good way of explaining ina simple way..
Thanks
Jeg | | | | | | Thanks Jag for the enlightening article on Reference cursors...it was a lot more... | | | | | | Thanks allot for providing us a very good description on Ref Cursors. I found this... | | | | | | Excellent steps of understanding REFCURSOR concept with simple example... | | | | | | This is an example of telling a complex thing in a SIMPLE way. Hats off to you.... | | | | | | Thanks a lot for the post. This is good article and keep posting things with similar... | | | | | | The Content is Very Useful for my Knowledge and more than This is Really a Good Work... | | | | | | Itīs only confused to use ref cursor in page 1-3.
The only reason to use ref cursor... | | | | | | has anybody tried using ref cursor in 10g. Because I have a proc which passes ref... | | | | | | The examples posted here are really helpful and can be easily comprehended.
If you... | | | | | | this topic civering ref cursors was very good. especially for beginners!!! | | | | | | its great to peek into it for 2 minutes and to get in hand all the imp points reg... | | | | | | Excellent article! Thanks. | | | | | | Really helpful. In less than 15 min I could get everything I ever wanted to know... | | | | | | its great to peek into it for 2 minutes and to get in hand all the imp points reg... | | | | | | Dear Sir,
Realy its very easy to study and understand...Thanx for... | | | | | | This is really good presentation for understanding the ref_cursors topic .
this is... | | | | | | Very nice artical. It gives very clear idea of ref cursor. Thank you for this. | | | | | | very helpfull | | | | | | You are amazing. If all programming books were written the way you do, learning to... | | | | | | Dear Jagadish,
I wish other authors 'learned' the flow and style that you use.
It... | | | | | | Hi sir,
Basically before i read this article i have a little idea on REF... | | | | | | How do you use a ref cursor,in PL/SQL, when you don't know the number of columns... | | | | | | It seems like you could do it in PL/SQL, but you can't before version 11g. Variable... | | | | | | Good explanation, however just like to point out one flaw with the... | | | | | | Hi Sir
This article is very good and very usefull to me, the way of... | | | | | | explanation of this topic is awesome.....and I enjoyed working with this ref... | | | | | | Its really a best example for understanding a REF Cursor in PL/SQL.I am sure if any... | | | | | | Excellent article. The author can read minds of his readers. | | | | | | This is v.good example for the beginners | | | | | | Hi jagadish,
Very good explanation.It gave a clear understanding of... | | | | | | gud job:)) | | | | | | This article is very useful for me as a beginner.Thank u very much for your good... | | | | | | Excellent explanation!!! Whenever I go through any article in DevShed regarding... | | | | | | Thank you very much for this sort of step by step deliberation. I hope it will help... | | | | | | dear sir,
this article is very use full for me.
Thanks a lot.
from,... | | | | | | >>> Post your comment now! | | | | | |
|
 |