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
Using %ROWTYPE The %ROWTYPE attribute gives a record type which represents a row in a table (or view). The record can store the whole row of data selected from the table or fetc

IN Mode An IN parameter pass the values to the subprogram being called. Within the subprogram, an IN parameter acts like a constant. And hence, it cannot be assigned a value.

(a) What are decision support systems, and what role do they play in the business environment? (b) Data warehousing is defined as "a subject-oriented, integrated, non-volatile c

query to Find the account numbers of all customers whose balance is more than 10,000 $

Some Varray Examples In SQL Plus, assume that you define an object type Project, as described below: SQL> CREATE TYPE Project AS OBJECT ( 2 project_no NUMBER(2), 3 title VARCHA

Application to Export Excel Data to MSSQL Server table I am having a table available in excel format and features the subsequent: - Some text is in Arabic (e.g. UTF-8 encodin

Fetching with a Cursor The FETCH statements retrieve the rows in the result set one at a time. After each and every fetch, the cursor advance to the next row in the result set

Updating by replacement Syntax: UPDATE ENROLMENT SET Name = 'Ann' WHERE StudentId = SID ('S1'); Note the use of SET, as already noted in connection with direct a

Need Database Development with Analysis Tools Project Description: I want a database for large governmental and private data sets on one country that can be simply extended t

Using SET TRANSACTION You use the SET TRANSACTION statement to begin the read-only or read-write transaction, start an isolation level, or assign your present transaction to a