Plsql two attribute types%type and%rowtype

Source: Internet
Author: User

1.%type

You can use%type when you define a variable whose data type is the same as the type of a data variable that you have defined, or is the same as the data type of a column in a database table.
To put it bluntly is to assign the result of a column you are querying to a variable that will use the%TYPE.

---to inquire about the declareempcom Emp.comm%type of the employee number 7369 subsidy;  -- Declare a empcom variable with data type Type Comm column type of EMP table begin   Select comm into empcom from EMP where empno=7369;--- Place the result value of the Comm type found in the empcom variable    dbms_output.put_line (' Employee subsidy is ' | | empcom);---| | is the connection character end;

The Declare declaration section defines a empcom variable whose type is the Comm property of the EMP, meaning that the next program assigns the value of the column to the empcom variable.
Select Comm to empcom from EMP where empno=7369;
Select ... into ... Indicates that the query result is assigned to empcom.

2.%rowtype

PL/SQL provides the%rowtype operator, which returns a record type whose data type is consistent with the data structure of the database table.

How to use: Variable name. Column Name
The advantage of using the%rowtype feature is that:
The number of columns in the referenced database and the data type can be unnecessary to know;
The number of columns and data types in the referenced database can be changed in real time.
The records that take out a column can be stored in a variable defined using RowType.

---query all the information of King employees. %rowtype using declareempmsg emp%rowtype; --Define a empmsg variable to save a row of data begin  

  

Plsql two attribute types%type and%rowtype

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.