PL/SQL three special data types

Source: Internet
Author: User

In addition to the basic types specified by orecle, PL/SQL provides 3 special data types%type types, record types, and%rowtype types.

"%type Type"

You can use%type to declare a data type that is the same as the specified column name, for example: v_id Emp.id%type is a variable of the same type as the ID field in the EMP table.

There are two advantages to using%type to define a variable: First, you do not have to look at the data type of each column in the table when defining the variable, and second, if the column data types in the table are modified, the variables defined with%type are automatically adjusted.

"Record Type"

Also known as record types, variables that use the record can store a row of data consisting of multiple column values. Use the following methods:

Declare

Type Emp_type is record (---------------------declares the record type Emp_type

V_ID Emp.id%type;

V_name Emp.name%type;

)

Empinfo Emp_type; -------------------declares a variable of type Emp_type empinfo

Begin

Select ID name into Empinfo from EMP where id=1;

/*

Query the EMP table for a record with ID 1 assigned to Empinfo

*/

Dbms_output.put_line (empinfo.v_id| | ' ==========> ' | | Empinfo.v_name);

End

【 】

Variables of type%rowtype combine the advantages of the%type type and the record type, which can be used to store a record based on the structure of the rows in the table that defines the data type. For example:

Declare

Empinfo Emp%rowtype;

Begin

SELECT * into Empinfo from EMP where id=1;

Dbms_output.put_line (empinfo.id| | ' ========> ' | | Emp.name);


End


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.