集合是将相同类型的多个变量当作一个整体进行处理。方便变量的管理,使程序中不至于定义太多的变量。
记录是将多个不同类型的变量当作一个整体进行处理。
记录的使用:
declare
type user_type is record(
user_name varchar2(10),
user_id number(10),
password varchar2(20)
);
user_info user_type;
begin
select username,user_id,password into user_info from t_user where user_id=&userid;
dbms_output.put_line(user_info.user_name||' '||user_info.password);
end;
集合的使用:适合处理多行一列的情况
declare
type user_table is table of varchar2(20) index by binary_integer;
userlist user_table;
cursor usercursor is
select username from t_user;
begin
if not usercursor%isopen then
open usercursor;
end if;
fetch usercursor bulk collect
into userlist;
for i in 1 .. userlist.count loop
dbms_output.put_line(userlist(i));
end loop;
close usercursor;
end;