What are the tables in the Oracle composite type?

Source: Internet
Author: User

The following articles mainly describe Oracle composite types and the detailed introduction of several types of variables in Oracle databases. The following is a detailed description of the article. I hope you will be able to learn more about Oracle composite types.

There are several types of variables in Oracle: Numeric

Character Type

Reference Type

Compound

Oracle composite types include: table and array

Table tables can also be divided into: 1. index table 2. nested table

I. index table:

Definition: The table names in the exercise are v_table)

Type index table Name is table of type index by binary_integer;

Usage: Because the index table name cannot be used directly, a variable is defined first.

 
 
  1. v_temptable_table v_table;  

Index Table features:

① There are only two columns in the index table

② It can only be stored in memory

③ You cannot use DML operations.

④ Easy to use

Index table exercise

Declare

Define index table

 
 
  1. type v_table is table of emp%rowtype index by binary_integer; 

Define index table Variables

 
 
  1. v_emp v_table;  
  2. cursor cur_emp is select * from emp;  
  3. v_num number:=0;  
  4. begin 

Put every piece of data in EMP into the index table q

 
 
  1. for v_e in cur_emp loop  
  2. v_numv_num:=v_num+1;  
  3. select * into v_emp(v_num) from emp where ename=v_e.ename;  
  4. end loop; 

Output the name of each record

 
 
  1. for I in 1..v_emp.count loop  
  2. dbms_output.put_line(v_emp(i).ename);  
  3. end loop;  
  4. end;  
  5. /  

Ii. nested tables:

Definition: (The table names in the exercise are v_nested)

Type table name is table of type;

Use: define variables and initialize them.

 
 
  1. v_my_nested v_nested := v_nested(‘aa’,’bb’);  

Features:

1. DML operations are supported.

2. Initialization is required before use.

3. Extended using the EXTEND Method

Exercise:

 
 
  1. declare  
  2. type v_nested is table of varchar2(20);  
  3. v_my_nested v_nestedv_nested:=v_nested('aa','bb'); 

Initialization

 
 
  1. begin  
  2. v_my_nested.extend(3);  
  3. v_my_nested(5):='ee';  
  4. end;  

3. array: array

Definition:

Type array name is varry (maximum value limit) of type;

Note: initialization is performed first and DML operations can be performed.

 
 
  1. v_my_varry[100]:=v_varray('aa','bb');   
  2. declare  

Defines the maximum limit of 100 for an array.

 
 
  1. type v_array is array(100) of emp.ename%type; 

Define array variables and Open Space

 
 
  1. v_arr v_arrayv_array:=v_array();  
  2. cursor cur_emp is select * from emp;  
  3. v_num number:=0;  
  4. begin  
  5. v_arr.extend(100);   
  6. for v_e in cur_emp loop  
  7. v_numv_num:=v_num+1;  
  8. select ename into v_arr(v_num) from emp where ename=v_e.ename;  
  9. end loop;  
  10. for I in 1..v_arr.count loop  
  11. dbms_output.put_line(v_arr(i));  
  12. end loop;  
  13. end;  
  14. /  

Iv. Oracle composite type Method:

The keyword extend is only used in nested tables and arrays.

Count is used to calculate the length.

First points to the first

Extended Space count

Last points to the Last

Exist to determine whether there is a is not null does not exist is null

Next move down

Priev move up

Delete (n) delete record n you can specify a specific row)

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.