cursor c1 is select * from test;
rst c1%rowtype;
begin
open c1;
fetch c1 bulk collect into rst;
close c1;
end;
类型声明不是这样用的,也不是用在这地方的!
rst c1%rowtype;
begin
open c1;
fetch c1 bulk collect into rst;
close c1;
end;
类型声明不是这样用的,也不是用在这地方的!
调试欢乐多
加上
loop
exit when c1%notfound;
fetch c1 into rst;
end loop;
。
不管是否使用游标,怎么把一个结果集bulk collect into 到一个变量中,怎么来实现阿?
例如:
declare type t_test is table of test%rowtype;
rs_test t_test;
cursor c1 is select * from test;
begin
open c1;
fetch c1 bulk collect into rs_test;
close c1;
end;就像上面的例子,总是报错,不是知道是否能做到,还是根本就行不通?
插入到某个值的话,要
fetch rst.column into rs_test;
You can bulk-fetch from a cursor into a collection of records:DECLARE
TYPE DeptRecTab IS TABLE OF dept%ROWTYPE;
dept_recs DeptRecTab;
CURSOR c1 IS SELECT deptno, dname, loc FROM dept WHERE deptno > 10;
BEGIN
OPEN c1;
FETCH c1 BULK COLLECT INTO dept_recs;
END;实在不行就这么写:declare
i pls_integer;
type r_st is table of test%rowtype;
rst r_st:=r_st();
cursor c1 is select * from test;
begin
i:=1;
open c1;
loop
rst.extend();
fetch c1 into rst(i);
exit when c1%notfound;
i:=i+1;
end loop;
close c1;
for i in rst.first..rst.last loop
dbms_output.put_line(rst(i).column1||' '||rst(i).column2);
end loop;
end;
首先非常感谢你,对我的问题给予了详细的解答!我也是看到<<PL/SQL USER GUIDE AND REFERENCE>>9.0.2上这么一个例子的时候,
运行总是不对,才提出的这个问题,现在看来有可能是我的oracle的版本(我的是
SQL*Plus: Release 9.0.1.0.1 - Production)不对
所以才运行通不过的。不知道大家试过没有。