Plsql records a struct struct in a similar language, facilitates the processing of single-row multi-column data, and Plsql records are composed of a set of related record member field, which are basically two types of use:
custom field and type, which is generally satisfied with single-row multi-column not all columns
TYPE Emp_record_type1 is RECORD (custom field
V_name VARCHAR2 (20),
V_sal Number (6,3)
);
Emp_record1 Emp_record_type1;
TYPE Emp_record_type2 is RECORD (field with original table
V_name EMP. Ename%type,
V_sal EMP. Sal%type
);
Emp_record2 emp_record_type2;
Custom is generally used when the column is not a full table
DECLARE
TYPE Emp_record_type2 is RECORD (field with original table
V_name EMP. Ename%type,
V_sal EMP. Sal%type
);
Emp_record emp_record_type2;
BEGIN
SELECT ename,sal to Emp_record from EMP;
Dbms_output. Put_Line (Emp_record. V_name);
END;
Second, through the%rowtype property can be based on a table or attempt to define record variables, this definition of record variables, member names and types are identical to the original table, if only a few columns, you should use a custom record type and variables.
IDENTIFIER Table_name%rowtype;
IDENTIFIER View_name%rowtype;
Dept_record Dept%rowtype;
Emp_record Emp%rowtype;
Declare
Type Emp_cursor is a select * from EMP;
Emp_record Emp_cursor%rowtype;
Begin
Open emp_cursor;
Loop
Fetch emp_cursor into Emp_record;
Exit when Emp_cursor%notfound;
Dbms_output.put_line (emp_record.ename| | Emp_record.sal);
End Loop;
Close emp_cursor;
End
This article from "Yun Weibang" blog, declined reprint!
Plsql record and RowType type