Table-based records

The PL/SQL table-based records are essentially a way of representing data in a tabular format. This means that each row corresponds to a record, and each column corresponds to a field within that record. You can think of it as a way of representing data in a spreadsheet-like format.

Table-based records are a powerful way of representing and manipulating data in Oracle PL/SQL. They offer a more structured way of working with data, and can be used to make your code more readable and maintainable.

To create and declare a table record use the PL/SQL %ROWTYPE attribute. Then use a select query to load the declared table-based with records. The syntax for the PL/SQL table-based records is as follows:

Syntax

DECLARE
	table_record table_name%rowtype;
BEGIN
	SELECT * INTO table_record
	FROM table_name;	
	DBMS_OUTPUT.PUT_LINE
	('Col_1: '||table_record.column1||' Col_2: '||table_record.column2);
END;

Example

Phones table

PHONE_IDPHONE_NAMEPRICE
1Galaxy Note Edge700
2N910 Galaxy Note 4600
3Galaxy S5 Duos 4G500
4iPhone 5S600
5iPhone 6 Plus900

Table-based records

DECLARE
	rec PHONES%rowtype;
BEGIN
	SELECT * INTO rec
	FROM PHONES
	WHERE price = 900;
	
	DBMS_OUTPUT.PUT_LINE
	('Id: '||rec.PHONE_ID||' Name: '||rec.PHONE_NAME||' Price: '||rec.PRICE);
END;
/

Output

Id: 5 Name: iPhone 6 Plus Price: 900