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
At times, Brewbean's has changed the id number for existing products. In the past, they have had to add a new product row with the new id to the BB_PRODUCT table, modify all the co

Transaction Visibility As the figure shows, the changes made by an autonomous transaction become visible to another transaction whenever the autonomous transaction commits. Th

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

What Are Subprograms? The Subprograms are named PL/SQL blocks which can take parameters and be invoked. The PL/SQL has 2 types of subprograms known as the procedure s and func

Overloading The PL/SQL overloads the subprogram names. That is, you can use similar name for few different subprograms as long as their formal parameters differ in the number

Example of NOT EXISTS in SQL Example: Use of NOT EXISTS CREATE ASSERTION Must_be_enrolled_to_take_exam_alternative1 CHECK ( NOT EXISTS (SELECT StudentId, CourseId

Mutual Recursion The Subprograms are mutually recursive if they directly or indirectly call each other. In the illustration below, the Boolean functions odd & even, that dete

Using SAVEPOINT The SAVEPOINT names and marks the present point in the processing of a transaction. Used with the ROLLBACK TO statement, the savepoints undo parts of a transac

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)

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,