1
我設置了一個遊標來獲取我的過程結果中的多行。但是,它似乎不會生成此錯誤消息: 「01422. 00000 - 」精確提取返回的請求行數多於「 *原因:在精確提取中指定的數量小於返回的行數 *行動:重寫查詢或更改請求的行數「爲什麼我的光標無法正常工作?
代碼的其他部分沒有問題,因爲我只有一條記錄時嘗試,它運行良好。但是當有多個記錄時,我的光標似乎不起作用。這是爲什麼?
set serveroutput on
declare
get_term scores.term%type;
get_sectno scores.sectno%type;
get_sid scores.sid%type;
get_score scores.points%type;
status boolean;
procedure total_score (aterm in out scores.term%type,
asectno in out scores.sectno%type,
asid out scores.sid%type,
ascore out scores.points%type,
status out boolean)
is
cursor find is
select scores.term, scores.sectno, sid, sum(points/maxpoints*weight)
from scores, components
where scores.term=components.term
and scores.sectno=components.sectno
group by scores.term, scores.sectno, sid;
find_rec find%rowtype;
begin
open find;
fetch find into find_rec;
while find%found loop
select scores.term, scores.sectno, sid, sum(points/maxpoints*weight)
into aterm, asectno, asid, ascore
from scores, components
where scores.term=components.term
and scores.term=aterm
and scores.sectno=components.sectno
and scores.sectno=asectno
and scores.compname=components.compname
group by scores.term, scores.sectno, sid;
status:=true;
fetch find into find_rec;
end loop;
close find;
exception
when no_data_found then
status:=false;
end;
begin
get_term:='F12';
get_sectno:='1031';
total_score (get_term, get_sectno, get_sid, get_score, status);
if (status) then
dbms_output.put_line(get_term||' '||get_sectno||' '||get_sid||' '||get_score);
else
dbms_output.put_line('Record not found.');
end if;
end;
我試圖用你的方法來重寫代碼,但它也不起作用。 「光標內部的選擇在一次或多次迭代中返回兩行或多行」是什麼意思?是不是遊標被用來處理多行? –
在遊標的每次迭代中,select必須返回一行以允許設置變量:變量 - 「一個值」。因此,在迭代中,如果select返回,例如兩個記錄,那麼在aterm,asectno,asid,ascore變量中插入哪些值?第一行的值?第二行的值? – Yellow75
我明白這一點。但是,如何在我的代碼中發生?你是說我的光標沒有正確定義,或者我沒有正確使用它?我該如何解決這個問題?謝謝。 –