ITPub博客

首页 > 数据库 > Oracle > PL/SQL 索引表例子

PL/SQL 索引表例子

原创 Oracle 作者:genweihua 时间:2015-09-16 20:58:46 0 删除 编辑

学习PL/SQL 索引表,一直只是看书,看着看着,觉得懂了,就写一段代码:

1、输入表的内容:

点击(此处)折叠或打开

  1. declare
  2.   type v_type is table of varchar2(100) index by binary_integer;
  3.   v_err v_type;
  4.   v_text varchar2(40);
  5. begin
  6.   select username bulk collect into v_err from v$session;
  7.   for i in v_err.first .. v_err.last loop
  8.     v_text := v_err(i);
  9.   dbms_output.put_line(v_text);
  10.   end loop;
  11. end;

2、用索引表里的数据,插入到新表中,当然也可以更新或者删除:


点击(此处)折叠或打开

  1. create table t_user(username varchar2(50));

  2. declare
  3.   type v_type is table of varchar2(100) index by binary_integer;
  4.   v_err v_type;
  5. begin
  6.   select username bulk collect into v_err from v$session;
  7.   forall i in v_err.first .. v_err.last
  8.     insert into t_user (username) values (v_err(i));
  9.   commit;
  10. exception
  11.   when others then
  12.     null;
  13. end;
在其中发现forall 语句只能和DML块一起用,这是最主要的发现,在这里mark一下!


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

上一篇: PL/SQL 索引表
请登录后发表评论 登录
全部评论
事了拂衣去,深藏功与名!

注册时间:2009-08-28

  • 博文量
    114
  • 访问量
    623621