Cursors in pl/sql, PL-SQL Programming

Cursors

The Oracle uses work areas to execute the SQL statements and to store process information. A PL/SQL construct known as the cursor. Let's you assume name a work area and access its stored information. There are 2 kinds of cursors: implicit and explicit. The PL/SQL implicitly declares a cursor for all the SQL data manipulation, together with queries that return only one row. For queries which return more than one row, you can explicitly declare the cursor to process the rows separately. An example is as shown:

DECLARE

CURSOR c1 IS

SELECT empno, ename, job FROM emp WHERE deptno = 20;

The set of rows returned by a multi-row query is known as result set. The size is the number of rows that meet your search criteria. As the figure shows, an explicit cursor points to the current row in the result set. This permits your program to process the rows one at a time.

854_cursors.png

Figure: Query Processing

The Multi-row query processing is somewhat like the file processing. For e.g., a COBOL program opens a file, processes records, and then closes the file. Similarly, a PL/SQL program opens a cursor, then processes rows returned by a query, and then closes the cursor. Now as a file pointer marks the current position in an open file, a cursor notes the current position in a result set.

You use the OPEN, CLOSE, and FETCH statements to control a cursor. The OPEN statement executes the query related with the cursor, identifies the result set, & positions the cursor before the first row. The FETCH statement retrieves the current row and advances the cursor to the next row. If the last row has been processed, the cursor is then disabling by the CLOSE statement.

Posted Date: 10/2/2012 1:15:27 AM | Location : United States







Related Discussions:- Cursors in pl/sql, Assignment Help, Ask Question on Cursors in pl/sql, Get Answer, Expert's Help, Cursors in pl/sql Discussions

Write discussion on Cursors in pl/sql
Your posts are moderated
Related Questions
Data Types in SQL - Timestamp TIMESTAMP for values representing points in time on a specified uniform scale. DATE is used for timestamps on a scale of one day, such as DATE '2

User-Defined Exceptions The PL/SQL defines the exceptions of your own. Dissimilar to the predefined exceptions, the user-defined exceptions should be declared and should be rai

Scope and Visibility The References to an identifier are resolved according to its visibility and scope. The scope of an identifier is that area of a program unit (subprogram, b

i NEED TO CREATE 3 guiS IN pl/sql sERVER PAGE FORM

Built-In Functions The PL/SQL provides a lot of powerful functions to help you to manipulate the data. These built-in functions fall into the categories as shown below: error r

EXCEPTION_INIT Pragma The pragma EXCEPTION_INIT relates an exception name with an Oracle error number. Which allow you to refer to any internal exception by the name and to wri

Collections:   The collection is an ordered group of elements, all of similar type (for illustration, the grades for a class of students). Each element has an exclusive subsc

Write a cursor to open an employee database and fetch the employee record whose age is greater than 45

%ROWCOUNT When its cursor or cursor variable is opened, the %ROWCOUNT is zeroed. Before the first fetch, the %ROWCOUNT yields 0. Afterward, it yields the number of rows fetche

Hi,am developing a library system and relating all the table is somehow complex,could you kindly assist me