Oracle -- plsql Composite data type

Source: Internet
Author: User


• Composite variables are also called composite variables. Composite variables include multiple internal components, and each component can store values separately. Therefore, a composite variable can store multiple values.
• The composite variable type is not an existing data type in the database. Therefore, before declaring a composite variable type, you must first create a composite type. The composite type can be used multiple times after being created, to define multiple composite variables. Composite data types include:-record-table-nested table-array record is a logical unit composed of a group of related data items. Each data item has its own name and data type. A table is a collection of data that can be referenced and processed as a whole. A table consists of columns and keywords, and rows can be accessed in groups through keywords. Once defined, record and table can be reused. PL/SQL Records • records are a group of related data items stored in multiple fields. Each field has its own name and data type. • Use a set of fields as a logical unit • It is mainly used to retrieve the queried row data records from a table. Features: • each record can contain many fields. • You can assign initial values to records, at the same time, not null can be used to limit Records • fields without initial values are defined as NULL • reserved words DEFAULT can also be used when defining fields • RECORD can be defined in the Declaration part of any block, subroutine or package type and declare User-Defined Records • can declare and reference nested records, a record can be a component Syntax of other records: [plain] TYPE type_name is record (field_declaration [, field_declaration]…); Field_declaration: [plain] field_name {field_type | variable % TYPE | table. column % TYPE | table % ROWTYPE} [[not null] {: = | DEFAULT} expr] [plain] TYPE emp_record_type is record (empno emp. empno % type, ename emp. ename % type, job varchar2 (9); emp_record emp_record_type; you can use the point number to reference the record_name.field_name % ROWTYPE attribute in the record. • The declared variables correspond to the set of columns in the database table or view. • Add the database table name before % ROWTYPE • field in the record for the name and data type, refer to [plain] DECLARE emp in the table or view. _ Record emp % rowtype ;.... Emp_record.ename = 'ljs'; emp_record.sal = 3000; SELECT * INTO emp_record FROM emp WHERE ......; Advantages of % ROWTYPE: • you do not need to know the number and type of columns in the database. • During running, the number and type of columns in the database may change. • This attribute can be used in SELECT statements to effectively retrieve rows in a TABLE and create PL/SQL tables [plain] TYPE type_name IS table OF {column_type | variable % TYPE | TABLE. column % TYPE} [not null] [index by BINARY_INTEGER]; identifier type_name; [plain] declare type ename_table_type is table of emp. ename % type index by BINARY_INTEGER; TYPE partition is table of date index by BINARY_INTEGER; ename_table ename_table_type; hiredate_table partition; BEGIN ename_table (1): = 'cameron '; hiredate_table (8 ): = SYSDATE + 7; IF ename_table.EXISTS (1) then insert ...... END; table method:
Author shaojie519

Related Article

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.