473,420 Members | 4,510 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,420 developers and data experts.

Oracle REF CURSOR - 2

debasisdas
8,127 Expert 4TB
Cursor Variable Returning %ROWTYPE
-----------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE TmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
  3. tmp_cv TmpCurTyp;TYPE EmpCurTyp IS REF CURSOR RETURN tmp_cv%ROWTYPE;
  4. emp_cv EmpCurTyp;
  5. BEGIN
  6. NULL;
  7. END;
Cursor Variable Returning %TYPE
---------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. dept_rec dept%ROWTYPE;
  3. TYPE DeptCurTyp IS REF CURSOR RETURN dept_rec%TYPE;
  4. dept_cv DeptCurTyp;
  5. BEGIN
  6. NULL;
  7. END;
  8.  
Cursor Variable Returning Record Type
-----------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE EmpRecTyp IS RECORD (
  3. employee_id NUMBER,
  4. last_name VARCHAR2(30),
  5. salary NUMBER(7,2));
  6. TYPE EmpCurTyp IS REF CURSOR RETURN EmpRecTyp;
  7. emp_cv EmpCurTyp;
  8. BEGIN
  9. NULL;
  10. END;
Passing Cursor Variables As Parameters
--------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
  3. ct EmpCurTyp;
  4. PROCEDURE process_emp_cv (emp_cv IN EmpCurTyp) IS
  5. person emp%ROWTYPE;
  6. BEGIN
  7. dbms_output.put_line('-----');
  8. dbms_output.put_line('Here are the names from the result set:');
  9. LOOP
  10. FETCH emp_cv INTO person;
  11. EXIT WHEN emp_cv%NOTFOUND;
  12. dbms_output.put_line('Name = ' || person.ename ||' ' || person.job);
  13. END LOOP;
  14. END;
  15. BEGIN
  16. OPEN ct FOR SELECT * FROM emp WHERE ROWNUM < 11;
  17. process_emp_cv(ct);
  18. CLOSE ct;
  19. OPEN ct FOR SELECT * FROM emp WHERE ename LIKE 'A%';
  20. process_emp_cv(ct);
  21. CLOSE ct;
  22. END;
  23.  
another sample code
================
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
  3. emp_cv EmpCurTyp;
  4. rr emp%rowtype;
  5. BEGIN
  6. IF NOT emp_cv%ISOPEN THEN
  7. OPEN emp_cv FOR SELECT * FROM emp;
  8. END IF;
  9. loop
  10. fetch emp_cv into rr;
  11. dbms_output.put_line(rr.ename||' '||rr.job);
  12. exit when emp_cv%notfound;
  13. end loop;
  14. CLOSE emp_cv;
  15. END;
Sample Program Showing Fetching from a Cursor Variable into a Record
================================================== =====
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
  3. emp_cv EmpCurTyp;
  4. emp_rec emp%ROWTYPE;
  5. BEGIN
  6. OPEN emp_cv FOR SELECT * FROM emp WHERE sal < 3000;
  7. LOOp
  8. FETCH emp_cv INTO emp_rec;
  9. dbms_output.put_line('Name = ' || emp_rec.ename || ' ' ||emp_rec.job);
  10. EXIT WHEN emp_cv%NOTFOUND;
  11. END LOOP;
  12. CLOSE emp_cv;
  13. END;
  14.  
Also check Oracle REF CURSOR - 3
May 29 '07 #1
0 8020

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:
SAMPLE CODE TO SHOW USE OF REFCURSOR ======================================= EXAMPLE #1 ---------------------- declare --declare the fer cursor. type my_ref_cur_typ is ref cursor; --declare...
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...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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.