欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Oracle 数组使用整理

程序员文章站 2024-03-20 22:53:46
...
declare 
ct integer;
type arr is varray(12) of varchar2(8);
months arr := arr('201901','201902','201903','201904','201905'); 
begin
  
  dbms_output.put_line(months.count);--实际数量
  dbms_output.put_line(months.limit);--容量
  
  for k in 1..months.count loop
     dbms_output.put_line(months(k));
  end loop;
  
  for k in months.first..months.last loop
     dbms_output.put_line(months(k));
  end loop;
  
  ct :=1;
  while ct is not null loop
    dbms_output.put_line(months(ct));
    ct := months.next(ct);
  end loop;
  
  /*
  --下标超出数量
  dbms_output.put_line(months(6));
  months(6) := '201906';
  months(7) := '201907';
  months(8) := '201908';
  */
  
  months.extend(3);
  months(6) := '201906';
  months(7) := '201907';
  months(8) := '201908';
  dbms_output.put_line(months.count);
  
  months.trim();--删除最后一个元素
  months.trim(months.count);
  months.delete();
  
  for k in 1..months.count loop
     dbms_output.put_line(months(k));
  end loop;
  
end;

 

相关标签: 数据库 Database