473,421 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,421 developers and data experts.

Oracle REF CURSOR - 1

debasisdas
8,127 Expert 4TB
SAMPLE CODE TO SHOW USE OF REFCURSOR
=======================================
EXAMPLE #1
----------------------
Expand|Select|Wrap|Line Numbers
  1. declare
  2. --declare the fer cursor.
  3. type my_ref_cur_typ is ref cursor;
  4. --declare a variable of rec cursor type.
  5. my_ref_cur my_ref_cur_typ;
  6. my_rec dept%rowtype;
  7. my_rec1 emp%rowtype;
  8.  
  9. begin
  10. --open the cursor variable to select from a table.
  11.    open my_ref_cur for select * from dept;
  12.    loop
  13.        fetch my_ref_cur into my_rec;
  14.      dbms_output.put_line(my_rec.deptno||' '||
  15.    my_rec.dname||' '||my_rec.loc);
  16.  
  17.  exit when my_ref_cur%notfound;
  18.     end loop;
  19. --close the cursor.
  20. close my_ref_cur;
  21.  
  22. --open the same cursor to select from another set of ecords.
  23.    open my_ref_cur for select empno,ename,job from emp;
  24.    loop
  25.        fetch my_ref_cur into my_rec1.empno,my_rec1.ename,my_rec1.job;
  26.       dbms_output.put_line(my_rec1.empno||' '||
  27.       my_rec1.ename||' '||my_rec1.job);
  28.        exit when my_ref_cur%notfound;
  29.     end loop;
  30. close my_ref_cur;
  31.  
  32. end;
  33.  
EXAMPLE #2
----------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE R1_CUR IS REF CURSOR;
  3. MYVAR1 R1_CUR;
  4. ename1 varchar(10);
  5. sall number;
  6. no number;
  7. begin
  8.  
  9. no:=&no;
  10.  
  11. if no=10 then
  12. open myvar1 for select sal from emp1 where empno=7900;
  13. fetch myvar1 into  sall;
  14. dbms_output.put_line(sall);
  15. close myvar1;
  16. else
  17. open myvar1 for select ename from emp1 where empno=7900;
  18.  
  19. fetch myvar1 into ename1;
  20.  
  21. dbms_output.put_line(ename1);
  22.  
  23. close myvar1;
  24. end if;
  25. end;
  26.  
  27.  
EXAMPLE #3
----------------------
Expand|Select|Wrap|Line Numbers
  1. declare
  2. type ordertype is record(
  3. orderno varchar2(5),
  4. odate date,
  5. vencode varchar2(5),
  6. ostatus char(1),
  7. del_date date);
  8.  
  9. type ordercur is ref cursor return order_master%rowtype;
  10. order_cv ordercur;
  11. order_rec ordertype;
  12.  
  13. begin
  14.  
  15. open order_cv for select 
  16. orderno,odate,vencode,ostatus,del_date from order_master
  17. where vencode='v001';
  18. loop
  19. fetch order_cv into order_rec;
  20. exit when order_cv%notfound;
  21. dbms_output.put_line('The values are '||order_rec.orderno|| order_rec.odate ||' '||order_rec.vencode||' '||order_rec.ostatus||' '||order_rec.del_date);
  22.  
  23. end loop;
  24. close order_cv;
  25. end;
  26.  
Also check Oracle REF CURSOR - 2
May 29 '07 #1
0 4789

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
3
by: IGotYourDotNet | last post by:
Can anyone point me to some example ASP.NET apps that use Oracle has a backend and C# as the language? I need to figure out how to populate a drop down, and then a datagrid depending on what the...
2
by: André Nobre | last post by:
I don't know if this is the right place to make this question, so, if isn't, let me know... I have an oracle package with some procedures, and i need to access one procedure using vb.net. The...
6
by: JV | last post by:
A ref cursor data type can obviously be returned as an output parameter of a stored procedure, but can an ASP.NET application call an oracle proc that uses a ref cursor as an input parameter? If...
1
by: Chad | last post by:
Hi, I am a SQL Server programmer using Oracle for the first time. In our .NET client apps which use a SQL Server back end, we would use Stored Procedure exclusively for all database access for...
14
by: peteh | last post by:
Hi All; We have many production jobs that "load from cursor" to a UDB/AIX 8.2 (with dpf) data warehouse from source tables residing Oracle 9i. Since Oracle dates are (roughly) equivalent to DB2...
0
debasisdas
by: debasisdas | last post by:
RESTRICTIONS ON CURSOR VARIABLES ================================= Currently, cursor variables are subject to the following restrictions: Cannot declare cursor variables in a package spec. ...
2
by: Vinod Sadanandan | last post by:
All, Below listed are the new features in Oracle 11g ,please join me in this discussion to generate a testcase and analyze each of the listed features . Precompilers:...
0
debasisdas
by: debasisdas | last post by:
Cursor Variable Returning %ROWTYPE ----------------------------------------------------------- DECLARE TYPE TmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; tmp_cv TmpCurTyp;TYPE EmpCurTyp IS REF...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.