Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to understand pl/sql record

Shulou Source: shulou.com Published: 2022-06-01 03:44:37 09月15日 Update

Today, I would like to talk to you about how to understand pl/sql record. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.

PL/SQL records (record) are equivalent to structures in high-level languages and are useful for processing single lines of data. For example, when you want to retrieve an employee's name, salary, and benefits, if you use scalar variables to receive data, you need to define three variables. To simplify the processing of single-row, multi-column data, you can use records.

1. Define Record

When defining, it can be the developer and custom record types and record variables, or you can use% rowtype to define record variables directly.

For example: custom Record

DECLARE

TYPE emp_record_type IS RECORD (

Name emp.ename%type

Salary emp.sal%type

Dno emp.deptno%type

);

Emp_record emp_record_type

Emp_record is a record variable defined based on the record type emp_record_type. Record variable name: emp_record

2. Use the% rowtype attribute to define record variables

% rowtype can define record variables based on tables or views. When you use this property to define a record variable, the name and type of the record member are exactly the same as the column name and type of the table or view.

Syntax: identifier table_name%rowtype

When a record variable is defined using the% rowtype attribute, the number, name, and type of record members are the same as the number, name, and type of columns in the table or view.

For example:

Emp_record emp%rowtype

The member name of the record variable emp_record is the column name of the table emp (empno, ename..)

Examples of use:

Set serveroutput on

DECLARE

TYPE emp_record IS RECORD (

Name emp.ename%type

Salary emp.sal%type

Dno emp.deptno%type

);

Emp_record emp_record_type

BEGIN

Select ename,sal,deptno INTO emp_record

FROM emp

WHERE empno=&no

Dbms_output.put_line (emp_record.name)

END

When referencing a record variable member, you must prefix the member name with the record variable name.

After reading the above, do you have any further understanding of how to understand pl/sql record? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Variable type member name content attribute data view same number processing advanced three prefix masterpiece name salary more scalar knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Shulou Tech Info vpn Docker