RSS Feed

PL/SQL Table Based Records

Table Based Records

You define and declare records either in the declaration section of a PL/SQL block, or globally, via a package specification. A table-based record is one whose structure is drawn from the list of columns in the table. A table-based record is drawn from a particular table structure.

%TYPE and %ROWTYPE

%TYPE is used to declare a variable that is of the same type as a specified table’s column.

Emp_number emp.empno%type;

%ROWTYPE is used to declare a record i.e. a variable that represents the entire row of a table.

Emp_record emp%rowtype


An Example of PL/SQL Table Based Records

A simple example showing that a record named "customer_sales_data_rec" is declared based on the row of customer_sales_data table.
Create Table customer_sales_data (
 cust_id NUMBER(6),
 cust_name VARCHAR2 (200),
 total_sales NUMBER (14,2)
 );

DECLARE
 customer_sales_data_rec customer_sales_data%ROWTYPE;

BEGIN
 Do some processing..;
END;

No comments:

Post a Comment