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:



SELECT ename, sal, hiredate, deptno FROM emp;


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
Using LIMIT For nested tables, that have no maximum size, the LIMIT returns NULL. For varrays, the LIMIT returns the maximum number of elements that a varray can have (that yo

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

Assignments in pl/sql The Variables and constants are initialized every time a block or subprogram is entered. By default, the variables are initialized to NULL. Therefore, unle

ROWNUM The ROWNUM returns a number representing the order in which a row was selected from the table. The first row selected has a ROWNUM of 1; the second row has a ROWNUM of

Package STANDARD package named STANDARD defines the PL/SQL atmosphere. The package specification globally declares the exceptions, types, and subprograms that are available a

Using the Collection Methods The collection methods below help to generalize the code and make collections easier to use and also make your applications easier to maintain:

Use Bulk Binds If SQL statements execute inside a loop using the collection elements as bind variables, context switching between the PL/SQL & SQL engines can slow down the ex

Control Structures The Control structures are the most important PL/SQL extension to the SQL. Not only does PL/SQL let you manipulate Oracle data, it lets you process the data

Use External Routines The PL/SQL is particular for the SQL transaction processing. Therefore, several tasks are more quickly completed in a lower-level language like C that is

Declaring Records Whenever you define a RECORD type, you may declare records of that type, as the illustration shows: DECLARE TYPE StockItem IS RECORD ( item_no INTEG