How can I loop through a recordset?
Err… what version of recordset are you talking about?
There’s some differences between how the collections are handled vs the
object collections. The examples others have given you have been collection
based.
Object type collections are handled slightly differently. Since others have
given you samples of non-Object collections, here’s a very basic object
definition and use:
*** Code Start ***
CREATE OR REPLACE TYPE fruit_obj_typ AS OBJECT
(fname VARCHAR2(10), fcolor VARCHAR2(10));
CREATE OR REPLACE TYPE fruit_col_typ AS TABLE OF fruit_obj_typ;
DECLARE
. tab_fruit fruit_col_typ := fruit_col_typ();
BEGIN
. --
. – Fill your fridge…
. --
. tab_fruit.EXTEND;
. --
. -- The object reference is an inherent function, all values must be present...
. --
. tab_fruit(1) := fruit_obj_typ('Apple', 'red');
. tab_fruit.EXTEND;
. --
. -- ... unless the record is initialized to null first
. --
. tab_fruit(2) := fruit_obj_typ(NULL, NULL);
. tab_fruit(2).fname := 'Orange';
. --
. -- Report on the fruit in your fridge
. --
. DBMS_OUTPUT.PUT_LINE('Fruit Name: ' || 'Fruit color:');
. DBMS_OUTPUT.PUT_LINE('----------- ' || '------------');
. FOR num_idx IN tab_fruit.FIRST .. tab_fruit.LAST LOOP
. DBMS_OUTPUT.PUT_LINE(RPAD(tab_fruit(num_idx).fname, 12, ' ') ||
NVL(tab_fruit(num_idx).fcolor, 'Unknown'));
. END LOOP;
. --
. -- Clean out your fridge, it is past expiry date
. --
. tab_fruit.DELETE;
END;
*** Code End ***
Notes: