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
LOOP Statements The LOOP statements execute a series of statements at multiple times. The loops enclose the series of statements that is to be repeated. The PL/SQL provides typ

Structure of an Object Type: Similar to package, an object type has 2 parts: the specification and the body. The specification is the interface to your applications; it declar

Use the PLS_INTEGER Datatype When you require to declare an integer variable, use the datatype PLS_INTEGER that is the most efficient numeric type. That is as the PLS_INTEGER

This is a Customer Management project. Customer data is presented in a text file. The program will load this text data into its DB columns. The data mapping is user definable. User

Effect of Anonymous Columns Now, recall that a VALUES expression denotes a table with undefined column names. If an initial value is to be specified when a base table is creat

Using NOT NULL Besides assigning an initial value, the declarations can impose the NOT NULL constraint, as the example below shows: acct_id INTEGER(4) NOT NULL := 9999; You ca

Declaring Subprograms   You can declare subprograms in any PL/SQL subprogram, block, or package. But, you should declare subprograms at the end of the declarative part after a

Autonomous versus Nested Transactions Though an autonomous transaction is started by the other transaction, it is not a nested transaction for the reasons shown below: (i)

Packaging Cursors   You can split a cursor specification from its body for placement in a package. In that way, you can change the cursor body without changing the cursor spec

I need SQL Data Base Project Description: Network SQL database and SQL Setup two 4 workstation Skills required are Data Entry, MySQL, SQL