您的位置:首页 > 数据库

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

2012-04-13 11:33 162 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  table integer