Cursors in pl/sql, PL-SQL Programming


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:



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.


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
Example of WHEN or THEN Constraints A concrete example showing how SQL supports WHEN/THEN constraints CREATE TABLE SAL_HISTORY (EmpNo CHAR (6), Salary INTEGER NOT NULL,

Assignment of Variable - Updating a Variable Syntax: SET SN = SID ('S2'); This can obviously be read as "set the variable SN to be equal in value to SID ( 'S2' )".

Example of Table Literal - SQL Example: A Table Literal (correct version) VALUES ('S1', 'C1', 'Anne'), ('S1', 'C2', 'Anne'), ('S2', 'C1', 'Boris'), ('S3', 'C3'

I want someone to write a TSQL function that returns the name of the ODBC DSN. I will use the queries below, to get information about the connection, but none of these return th

SELECT INTO Statement   The SELECT INTO statement retrieve data from one or more database tables, and then assigns the selected values to the variables or fields. Syntax:

DELETE Command - SQL Loosely speaking, DELETE removes some existing rows from its target table. Suppose the university decides that course C3 is to be withdrawn. Example shows

LAWS / RULES - Dollo's Law                     :           Living organisms do exhibit evolutionary irreversibility or evolution is irreversible. Williston's Law

Create a procedure named STATUS_SHIP_SP that allows a company to employee in the Shipping Department to update the status of an order to add shipping information. The BB_BASKETSTAT

Example of Foreign Key Constraint Example: Alternative formulation for 6.3 as a foreign key constraint ALTER TABLE EXAM_MARK ADD CONSTRAINT Must_be_enrolled_to_take_exam

Quantification in SQL To quantify something, as the theory book has it, is to state its quantity, to say how many of it there are. For example, in Tutorial D the expression CO