ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Collection type 处理

Collection type 处理

原创 Linux操作系统 作者:qykong1986 时间:2011-11-14 11:14:12 0 删除 编辑
定义:
create type NUM_T is table of number;
create type NUM_T_IDX is table of number index by PLS_INTEGER;

初始化:
T_NUM NUM_T := NUM_T();
对于index collection 不需要初始化, T_IDX_NUM NUM_T_IDX;

增加,删除元素:
对于non-index collection
T_NUM.extend: 集合末端增加一个元素, count 加1,值为null
T_NUM.extend(n): 集合末端增加n个元素, count 加n,值为null
T_NUM.extend(n,m): 集合末端增加n个元素,count加n,值为 T_NUM(M).
T_NUM.delete; 删除集合内的所有元素
T_NUM.delete(n); 删除下标为n的元素
T_NUM.delete(x,y): 删除下标从x到y的元素,如果x>y,则集合不变
T_NUM.trim:删除集合末的一个元素
T_NUM.trim(): 删除集合末的一个元素
T_NUM.trim(n): 删除集合末的n个元素
DECLARE
   TYPE CourseList IS TABLE OF VARCHAR2(10); 
   courses CourseList;
BEGIN
   courses := CourseList('Biol 4412', 'Psyc 3112', 'Anth 3001');
   courses.DELETE(courses.LAST);  -- delete element 3
   /* At this point, COUNT equals 2, the number of valid
      elements remaining. So, you might expect the next 
      statement to empty the nested table by trimming 
      elements 1 and 2. Instead, it trims valid element 2 
      and deleted element 3 because TRIM includes deleted 
      elements in its tally. */
   courses.TRIM(courses.COUNT);
   DBMS_OUTPUT.PUT_LINE(courses(1));  -- prints 'Biol 4412'
END;
/
对于 index collection:
直接赋值 T_IDX_NUM(1) := 10; T_IDX_NUM(3) := 30;
删除使用 delete 函数, trim与extend不可用

取collectin的元素,count值:
T_NUM.exits(n): 判断T_NUM(n)是否存在。
T_NUM.count(): 返回collection的元素个数
T_NUM.first: 返回第一个元素的下标
T_NUM.last: 返回最后一个元素的下标
T_NUM.next(n):返回下标为n的下一个下标
T_NUM.prior(n):返回下标为n的前一个下标
T_NUM(n): 返回下标为n的元素值


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24352994/viewspace-710915/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-11-12

  • 博文量
    2
  • 访问量
    1202