declare
type res_table_type is table of table_name%rowtype index by binary_integer;
res_table res_table_type;begin
select * into res_table from table_name;end;这样好像不行,有人能帮忙吗?
type res_table_type is table of table_name%rowtype index by binary_integer;
res_table res_table_type;begin
select * into res_table from table_name;end;这样好像不行,有人能帮忙吗?
cursor emp_cursor is select ename,sal from emp
where lower(job) = lower('&job');
type emp_table_type is table of emp_cursor%rowtype
index by binary_integer;
emp_table emp_table_type;
i int;
BEGIN
open emp_cursor;
loop
i:=emp_cursor%rowcount+1;
fetch emp_cursor into emp_table(i);
exit when emp_cursor%notfound;
dbms_output.put_line('姓名:'||emp_table(i).ename||',工资:'||emp_table(i).sal);
end loop;
END;
应该为
select * bulk collect into res_table from table_name;
对,就是应该加上bulk collect into ,当把一个集合赋值给一个集合变量(可能是索引表或记录表什么的)要用bulk collect
如果要用游标的形式,这样
declare
mycurs refcursor;
begin
open mycurs for select * from tablename;
....
end;
不过数据量大时尽量不要使用游标.