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_ID PHONE_NAME PRICE
1 Galaxy Note Edge 700
2 N910 Galaxy Note 4 600
3 Galaxy S5 Duos 4G 500
4 iPhone 5S 600
5 iPhone 6 Plus 900

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