ITPub博客

首页 > Linux操作系统 > Linux操作系统 > plsql_index by_table of_count_next_prior_last,first语法小测

plsql_index by_table of_count_next_prior_last,first语法小测

原创 Linux操作系统 作者:wisdomone1 时间:2010-08-15 22:28:09 2 删除 编辑

--table of--index by 元素引用测试
set serveroutput on
declare
 type table_type is table of number index by binary_integer;
 table1 table_type;
begin
 table1(1):=1;
 table1(2):=2;
 table1(3):=3;
 dbms_output.put_line(table1(1));
 dbms_output.put_line(table1(2));
 dbms_output.put_line(table1(3));
end;
/
1
2
3

PL/SQL procedure successfully completed.

SQL>

 


--测试index by 且table of 类型之count,next,prior,first,last,exists用法


SQL> declare
  2   type table_type is table of number index by binary_integer;
  3   table1 table_type;
  4    begin
  5    table1(1):=1;--为第1个slot提供值1
  6     table1(4):=4;--为第2个slot提供值4
  7     dbms_output.put_line(table1.count);--count表示共占用几个slot,未分配指定值的slot不会计数   --
  8    for i in table1.first..table1.last loop  --用first及last表示第1个及最后1个slot对应的值
  9     if table1.exists(i) then  --用exists判断对应slot是否分配指定了值,避免触发异常no_data_found
 10     dbms_output.put_line(table1(i));
 11    else
 12    dbms_output.put_line('no data in slot '||i);--用else触发异常
 13    end if;
 14     end loop;
 15    dbms_output.put_line(table1.prior(1));--prior表示上1个slot对应的值
 16     dbms_output.put_line(table1.next(0));--同上,下1个slot对应的值
 17    dbms_output.put_line(table1(4));
 18     dbms_output.put_line(table1.prior(5)); --delete 删除slot对应的值并释放内存
 19     dbms_output.put_line(table1.next(4));--返回的值为null
 20     end;
 21  /
2
1
no data in slot 2
no data in slot 3
4
1
4
4

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

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12689906