学习PL/SQL 索引表,一直只是看书,看着看着,觉得懂了,就写一段代码:
1、输入表的内容:
-
declare
-
type v_type is table of varchar2(100) index by binary_integer;
-
v_err v_type;
-
v_text varchar2(40);
-
begin
-
select username bulk collect into v_err from v$session;
-
for i in v_err.first .. v_err.last loop
-
v_text := v_err(i);
-
dbms_output.put_line(v_text);
-
end loop;
-
end;
2、用索引表里的数据,插入到新表中,当然也可以更新或者删除:
-
create table t_user(username varchar2(50));
-
-
declare
-
type v_type is table of varchar2(100) index by binary_integer;
-
v_err v_type;
-
begin
-
select username bulk collect into v_err from v$session;
-
forall i in v_err.first .. v_err.last
-
insert into t_user (username) values (v_err(i));
-
commit;
-
exception
-
when others then
-
null;
-
end;
在其中发现forall 语句只能和DML块一起用,这是最主要的发现,在这里mark一下!
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22275400/viewspace-1801556/
,如需转载,请注明出处,否则将追究法律责任。