PL/SQL中不通过游标把值添加到集合中

1.把多行单列的值添加到索引表中(通过RowNum):例如
declare
  type dname_table_type is table of scott.dept.dname%type
  index by binary_integer;
  dname_table dname_table_type;
  dcount number(2);
begin
  select count(*) into dcount from scott.dept;
  for i in 1..dcount loop
      select t1.dname into dname_table(i) from 
(select rownum rn,t.* from (select * from scott.dept)t)t1
      where t1.rn=i;
  end loop;
  
  for i in 1..dname_table.count loop
      dbms_output.put_line(dname_table(i));
  end loop;
end;
2.PL/SQL记录表把多行多列的值添加到集合中(RowType):例如:
 declare 
  type dname_table_type is table of scott.dept%rowtype
  index by binary_integer; 
  dname_table dname_table_type;
dcount number(2);
 begin 
  select count(*) into dcount from scott.dept;
  for i in 1..dcount loop 
        select t1.deptno,t1.dname,t1.loc into dname_table(i) from
  (select rownum rn,t.* from scott.dept t)t1 
where t1.rn=i; 
 end loop; 
for i in 1..dname_table.count loop
  dbms_output.put_line(dname_table(i).dname||' '||dname_table(i).deptno); 
end loop; 
 end;
3.PL/SQL记录表把多行多列的值添加到集合表中(ReCord),自定义二维表:例如:
 declare 
type dept_record_type is record( 
 deptno scott.dept.deptno%type,
   dname scott.dept.dname%type,
   dloc scott.dept.loc%type );
  type dname_table_type is table of dept_record_type(数据类型) 
  index by binary_integer; 
  dname_table dname_table_type;
dcount number(2);
 begin 
  select count(*) into dcount from scott.dept;
  for i in 1..dcount loop 
        select t1.deptno,t1.dname,t1.loc into dname_table(i) from
  (select rownum rn,t.* from scott.dept t)t1 
where t1.rn=i; 
 end loop; 
for i in 1..dname_table.count loop
  dbms_output.put_line(dname_table(i).dname||' '||dname_table(i).deptno); 
end loop; 
 end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值