Get the App
SLTechnology News&Howtos  ›  Database  › 

Memory Table in PLSQL-- Index By Table

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

In fact, a memory table is a bit like an array in java, but it is more powerful than an array.

1. First of all, let's briefly introduce the role of memory tables:

An index primary key made up of BINARY_INTEGER types

Fields of simple types or user-defined types as specific array elements

two。 How to use memory table types?

Define memory table types

TYPE type_name IS TABLE OF storage type (number, employees.last_name%TYPE, employees%ROWTYPE, varchar2)

INDEX BY (BINARY_INTEGER,varchar2 (80)..)

-varchar2 (80) indicates that subscripts can be accessed through strings, which is more powerful than arrays in java

Declare a variable of this type

Identifier type_name

3. Some properties and methods in memory table

Assignment:

Identifier (1): = 'Jams'-- this is index by binary_integer

Identifier ('A'): = 'Jams'-- this is index by varchar2

Unlike arrays in java, memory tables can use strings as subscript

3-1.count method:

Identifier.count-returns the number of rows in the memory table

3-2.exists method:

Identifier.exists (1)-determines whether an element with subscript 1 exists

3-3.first and last attributes:

First: the index that returns the first row

Last: returns the index of the last row

The usage of first and last:

Generally used in the case of traversing memory tables

For i in identifier.first.. Identifier.last loop .end loop

Two points must be noted here:

1. If there is no data in the memory table, but you traverse it in this way, you will report an error, so you should use the

Count method to make a judgment.

two。 What if the data subscript in the memory table is not contiguous?

For example, there are only identifier (2) and identifier (5) in memory tables.

When traversing to the subscript 1, 4, do exception or error handling, otherwise the error will be reported.

3-4.delete method:

Identifier.delete (1)-deletes the element with subscript 1 in the memory table

Identifier.delete-deletes all elements of the memory table

3-5.next and prior attributes:

Identifier.next (1)-returns the next row index in the memory table with subscript 1

Identifier.prior (2)-returns the index of the previous row in the memory table with a subscript of 2 rows

The function of INDEX BY BINARY_INTEGER is attached here.

-- http://blog.itpub.net/26690043/viewspace-722081/

Tags: Memory subscript type array method index row element attribute powerful function character string data this is can report function powerful variable only Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information Shulou Tech Info Huawei Microsoft