473,614 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Oracle REF CURSOR - 2

debasisdas
8,127 Recognized Expert Expert
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 8033

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

Similar topics

5
3485
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, because the dates must have quotes on each side. I just don't know how make the dates right. Well I'll just show you the code and some insert statements it generates. Could anyone please help me?
3
2667
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 user selected in the drop down box. thx
2
3008
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 problem is that i really don't know what this oracle procedure will return to vb.net. If I execute this normally, like ADO.NET Store Procedure, i'll get a DataSet/DataTable? What should i pass as parameter to "cC1" (in out - procedure P_G_CLI_I8)?
6
2819
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 so, how? What object do you pass as that parameter? We are using System.Data.OracleClient, but if necessary, we might be able to switch.
1
4351
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 increased security as well as the pre-compiled advantage. To minimize trips to the db server, we would often call SPs that return more than one recordset. For example: CREATE Stored Procedure HelloWorld As
14
4427
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 timestamps, we frequently use the date() function to "convert" from the Oracle date datatype to the DB2 date datatype. We have used this technique on over 20 Oracle tables for several months with no problem. One table in particular fails with a...
0
18018
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. CREATE PACKAGE emp_stuff AS TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; emp_cv EmpCurTyp; -- not allowed END emp_stuff;
2
14226
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: Additional Array INSERT and SELECT Syntax Support by Pro*C/C++ and Pro*COBOL Precompilers: Dynamic SQL Statement Caching in Pro*C/C++ and Pro*COBOL Precompilers: Fix Execution Plan in Pro*C/C++ and Pro*COBOL Precompilers: Flexible B Area Length...
0
4804
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 a variable of rec cursor type. my_ref_cur my_ref_cur_typ;
0
8179
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8621
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8272
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6087
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5538
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4049
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1712
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.