Records
Each row in a table has one or more columns of various datatypes. Similarly, a record is composed of one or more fields. There are three different ways to define a record, but once defined, the same rules apply for referencing and changing fields in a record.
The block below demonstrates the declaration of a record that is based directly on an underlying database table. Suppose that I have defined a table to keep track of my favorite books:
CREATE TABLE books ( book_id INTEGER, isbn VARCHAR2(13) title VARCHAR2(200), );
I can then easily create a record based on this table, populate it with a query from the database, and then access the individual columns through the record’s fields:
DECLARE my_book books%ROWTYPE; BEGIN SELECT * INTO my_book FROM books WHERE title = 'Oracle PL/SQL Programming, 4th Edition'; END;
Get Oracle PL/SQL for DBAs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.