oracle 集合操作

来源:互联网 发布:unity3d 联机 编辑:程序博客网 时间:2024/05/19 08:25
/*
oracle 集合操作函数
1.DELETE
Procedure
Deletes elements from collection.

2.TRIM
Procedure
Deletes elements from end of varray or nested table.

3.EXTEND
Procedure
Adds elements to end of varray or nested table.

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

5.FIRST
Function
Returns first index in collection.

6.LAST
Function
Returns last index in collection.

7.COUNT
Function
Returns number of elements in collection.

8.LIMIT
Function
Returns maximum number of elements that collection can have.

9.PRIOR
Function
Returns index that precedes specified index.

10.NEXT
Function
Returns index that succeeds specified index.
*/



declare
type s is table of pls_integer index by pls_integer;
type citypo is table of pls_integer index by varchar2(200);
citys citypo;
m pls_integer:=10;
geti pls_integer;
getj varchar2(200);
ss s;
function dealM(m pls_integer) return s is
rs s;
begin
  for i in 1..m loop
    rs(i):=i*10;
  end loop;
return rs;
end;
begin
ss:=dealM(m);

--用for循环处理
/*
for i in 1..10 loop
dbms_output.put_line(ss(i));
end loop;
*/

--用while循环处理index为数值
/*
geti:=ss.first;
while geti is not null loop
  dbms_output.put_line(ss(geti));
  geti:=ss.next(geti);
end loop;
*/

--用while循环处理index为字符串的
/*
citys('shenzhen'):=100;
citys('guangzhou'):=200;
citys('shanghai'):=1000;
citys('beijing'):=2000;
getj:=citys.first;
while getj is not null loop
dbms_output.put_line(citys(getj));
getj:=citys.next(getj);
end loop;
*/


end;