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
Relational Operators The relational operators permit you to compare randomly complex expressions. The list below provides the meaning of each operator:

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

Row Counterparts of Table Operators SQL does not have counterparts tuple rename, tuple projection, tuple extension, tuple join and tuple compose. To obtain the same effects as

Bulk Fetching The illustration below shows that you can bulk-fetch from a cursor into one or more collections: DECLARE TYPE NameTab IS TABLE OF emp.ename%TYPE; TYPE S

Deriving Predicates from Predicates in SQL The corresponding section in the theory book describes how predicates can be derived from predicates using (a) the logical connectiv

Closing a Cursor The CLOSE statements disable the cursor, and the result set becomes undefined. An illustration of the CLOSE statement as shown: CLOSE c1;

Need to change mysql query to PDO Project Description: I want someone to convert me 1 .php file that includes some sql/mysql stuff to PDO is a very small file. Skills requ

EXIT The EXIT statement forces a loop to done unconditionally. Whenever an EXIT statement is encountered, the loop is done immediately and controls the passes to the next statem

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

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