PL/SQL Record

PL/SQL Record Data Type – How to write syntax, example

The Record data type – defines a group of stored data in the form fields with the data type and name.
The Record data type can be used in the declarative section of a block, package, or subprogram.

The Record syntax is:

TYPE type_name IS RECORD (field_declaration[,field_declaration]...);

First example:

SET SERVEROUTPUT ON
DECLARE
	TYPE t IS RECORD (
		book_no books.id%TYPE,
		price books.price%TYPE,
		book_name books.title%TYPE);
	v_book t;
BEGIN
	SELECT id, price, title
	INTO v_book
	FROM books
	WHERE book_id = 210;
	DBMS_OUTPUT.PUT_LINE('The book with id:'||v_book.book_no||' and title '||v_book.book_name||' has the price '||v_book.price);
END;
SET SERVEROUTPUT OFF

Second example:

SET SERVEROUTPUT ON
DECLARE
	TYPE t IS RECORD (
		book_no books.id%TYPE,
		price books.price%TYPE,
		book_name books.title%TYPE);
	v_book t;
BEGIN
	DELETE FROM books 
	WHERE id=210 
	RETURNING id, price, title INTO v_book;
DBMS_OUTPUT.PUT_LINE('The book with id:'||v_book.book_no||' and title '||v_book.book_name||' has the price '||v_book.price);
END;
SET SERVEROUTPUT OFF