lightdb新特性--兼容oracle存储过程--联合数组

联合数组是一组键值对,每个键是一个*唯*一*的索引,索引的数据类型可以是字符串类型或整型。 索引以排序顺序存储,而不是创建顺序

 

和数据库表相似的是:

l   用户可以在不知道其位置的情况下访问它们。

而与数据库表不同的是:

l   关联数组不需要磁盘空间。

l   不能用 DML 语句操作。


联合数组语法如下:


举例:

DECLARE
  -- Associative array indexed by string:
 
  TYPE population IS TABLE OF NUMERIC  -- Associative array type
    INDEX BY VARCHAR(64);            --  indexed by string
 
  city_population  population;        -- Associative array variable
BEGIN
  -- Add elements (key-value pairs) to associative array:
  city_population('Smallville')  := 2000;
  city_population('Midland')     := 750000;
  city_population('Megalopolis') := 1000000;
  raise info 'Midland is %', city_population('Midland');
  raise info 'Smallville is %', city_population('Smallville');
  raise info 'Megalopolis is %', city_population('Megalopolis');
END;
/


结果如下:

INFO:  Midland is 750000
INFO:  Smallville is 2000
INFO:  Megalopolis is 1000000

访问数组元素通过使用圆括号操作,比如访问 city_population 数组中下标为 'Smallville' 的元素语法为 city_population('Smallville')

联合数组可以使用以下的方法来访问其中的元素。归纳如下:

Method Description

DELETE

Deletes elements from collection.

EXISTS

Returns  TRUE if and only if specified element of varray or nested table exists.

FIRST

Returns first index in collection.

LAST

Returns last index in collection.

COUNT

Returns number of elements in collection.


上面的使用方法如下:

array_name . method


请使用浏览器的分享功能分享到微信等