Plsql record and RowType type

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.