473,386 Members | 1,763 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,386 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 8015

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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...

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.