嘗試使用以下示例,在從光標可變emp_cv一個時間到用戶定義記錄EMP_REC提取行之一:
declare
TYPE YourType IS ref cursor return YourTable%rowtype;
tab_cv YourType;
tab_rec YourTable%rowtype;
begin
loop
fetch tab_cv into emp_rec;
exit when tab_cv%notfound;
...
end loop;
end;
散裝COLLECT子句允許您取結果集中的整個列或整個結果集。以下示例中,從一個遊標檢索列到收集:
declare
type NameList IS table of emp.ename%type;
names NameList;
cursor c1 is select ename from emp where job = 'CLERK';
begin
open c1;
fetch c1 bulk collect into names;
...
close c1;
end;
以下示例使用LIMIT子句。對於循環的每次迭代,FETCH語句將100行(或更少)讀入索引表acct_ids。以前的值被覆蓋。
declare
type NumList is table of number index by binary_integer;
cursor c1 is select acct_id from accounts;
acct_ids NumList;
rows natural := 100; -- set limit
begin
open c1;
loop
/* The following statement fetches 100 rows (or less). */
fetch c1 bulk collect into acct_ids limit rows;
exit when c1%notfound;
...
end loop;
close c1;
end;
您缺少'open curs1',應該先取,然後在未找到curs1%時使用exit。 –
謝謝!這是編輯錯誤,未經測試... :) –