Cursor for loops, PL-SQL Programming

Cursor FOR Loops

In most cases that need an explicit cursor, you can simplify the coding by using a cursor FOR loop rather of the OPEN, FETCH, and CLOSE statements. A cursor FOR loop implicitly declares its loop index as a record that shows a row fetched from the database. Then, it opens a cursor, repeatedly fetches rows of values from the result set into fields in the record, and after that closes the cursor when all rows have been processed. In the example below, the cursor FOR loop implicitly declares emp_rec as a record:

DECLARE

CURSOR c1 IS

SELECT ename, sal, hiredate, deptno FROM emp;

... BEGIN

FOR emp_rec IN c1 LOOP

...

salary_total := salary_total + emp_rec.sal; END LOOP;

To reference the individual fields in the record, you use dot notation, in which a dot (.) serves as the component selector.

Posted Date: 10/2/2012 1:16:05 AM | Location : United States







Related Discussions:- Cursor for loops, Assignment Help, Ask Question on Cursor for loops, Get Answer, Expert's Help, Cursor for loops Discussions

Write discussion on Cursor for loops
Your posts are moderated
Related Questions
Multiple Assignment- SQL SQL supports multiple assignment to local variables and also applies multiple assignment semantics in SET clauses of UPDATE statements, but does not

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,

Cursor Variables Similar to a cursor, cursor variable points to the current row in the result set of a multi-row query. But, dissimilar a cursor, a cursor variable can be opene

Special cases of projection This section describes the identity projection, r {ALL BUT}, and the projection on no attributes, r { }, which yields TABLE_DUM when r is empty, ot

Scope Rules You cannot declare an exception twice in the similar block. Though, you can, declare the similar exception in 2 different blocks. The Exceptions declared in a bloc

THEO R Y OF SPECIAL CREATION - Life originated on the earth due to natural events by the super natural power. The biblical story of creation of world within six days was p

Example of Shorthand for a row constraint Example: Shorthand for a row constraint ALTER TABLE EXAM_MARK ADD CONSTRAINT Mark_in_range CHECK (Mark BETWEEN 0 AND 100);

DELETE Statement The DELETE statement eliminates whole rows of data from the specified table or view. Syntax:

CLOSE Statement The CLOSE statement allows the resources held by a cursor variable or open cursor to be reused. No more rows can be fetched from the cursor variable or closed

Records Records are the items of the type RECORD. The Records have exclusively named fields that can store the data values of various types. And hence, a record treat associate