For each row in the cursor : rowtype « PL SQL « Oracle PL / SQL






For each row in the cursor

  
SQL>
SQL> set serveroutput on
SQL>
SQL> CREATE TABLE myStudent (
  2    student_id NUMBER(5) NOT NULL,
  3    department CHAR(3)   NOT NULL,
  4    course     NUMBER(3) NOT NULL,
  5    grade      CHAR(1)
  6    );

Table created.

SQL>
SQL> INSERT INTO myStudent (student_id, department, course, grade)
  2                           VALUES (10000, 'CS', 102, 'A');

1 row created.

SQL>
SQL> INSERT INTO myStudent (student_id, department, course, grade)
  2                           VALUES (10002, 'CS', 102, 'B');

1 row created.

SQL>
SQL> INSERT INTO myStudent (student_id, department, course, grade)
  2                           VALUES (10003, 'CS', 102, 'C');

1 row created.

SQL>
SQL> INSERT INTO myStudent (student_id, department, course, grade)
  2                           VALUES (10000, 'HIS', 101, 'A');

1 row created.

SQL>
SQL> INSERT INTO myStudent (student_id, department, course, grade)
  2                           VALUES (10001, 'HIS', 101, 'B');

1 row created.

SQL>
SQL> INSERT INTO myStudent (student_id, department, course, grade)
  2                           VALUES (10002, 'HIS', 101, 'B');

1 row created.

SQL>
SQL>
SQL> CREATE OR REPLACE PROCEDURE RSLoop AS
  2    v_RSRec myStudent%ROWTYPE;
  3    CURSOR c_RSGrades IS SELECT * FROM myStudent ORDER BY grade;
  4  BEGIN
  5    FOR v_RSRec IN c_RSGrades LOOP
  6      NULL;
  7    END LOOP;
  8
  9    DBMS_OUTPUT.PUT_LINE('Last row selected has ID ' || v_RSRec.student_id);
 10  END RSLoop;
 11  /

Procedure created.

SQL>
SQL>
SQL> drop table myStudent;

Table dropped.

   
  








Related examples in the same category

1.Use select command to fill value to rowtype variable
2.Define row type variable
3.Define rowtype and reference its column value
4.rowtype index by binary_integer
5.Use rowtype type value to query a table
6.Cursor and rowtype
7.From Fields to Rows-Using %ROWTYPE
8.Insert table%rowtype to table
9.Rowtype variable
10.Select * into table%rowtype
11.Select data into rowtype variable
12.fetch sys_refcursor type variable to table%rowtype variable