Defining and using a cursor-oriented record : ROWTYPE « PL SQL Data Types « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> create table product(
  2     product_id number(4)     not null,
  3     product_description varchar2(20) not null
  4  );

Table created.

SQL>
SQL> insert into product values (1,'Java');

1 row created.

SQL> insert into product values (2,'Oracle');

1 row created.

SQL> insert into product values (3,'C#');

1 row created.

SQL> insert into product values (4,'Javascript');

1 row created.

SQL> insert into product values (5,'Python');

1 row created.

SQL>
SQL>
SQL>
SQL>
SQL> DECLARE
  2    CURSOR csr_hrc IS
  3      SELECT * FROM product ORDER BY 1;
  4    myRecord csr_hrc%ROWTYPE;
  5  BEGIN
  6    OPEN csr_hrc;
  7
  8    LOOP
  9      FETCH csr_hrc INTO myRecord;
 10      EXIT WHEN csr_hrc%NOTFOUND;
 11      dbms_output.put_line(to_char(myRecord.product_id)||' '||myRecord.product_description);
 12    END LOOP;
 13    CLOSE csr_hrc;
 14  END;
 15  /
1 Java
2 Oracle
3 C#
4 Javascript
5 Python

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL>
SQL> drop table product;

Table dropped.








21.27.ROWTYPE
21.27.1.Declare ROWTYPE variable
21.27.2.Reference attribute in a ROWTYPE variable
21.27.3.Select value into the %ROWTYPE type variable
21.27.4.Using a Weak REF CURSOR and %ROWTYPE
21.27.5.Defining and using a cursor-oriented record
21.27.6.INSERT statement involving entire records
21.27.7.UPDATE statement involving entire records
21.27.8.Use rowtype with object table
21.27.9.rowtype.iterations
21.27.10.Use table column type as the record attribute type
21.27.11.Select * into table%rowtype
21.27.12.PLS-00382: expression is of wrong type