Oracle PLSQL LS-00382:表达式的类型错误

Oracle PLSQL LS-00382:表达式的类型错误,oracle,plsql,Oracle,Plsql,尝试运行此过程时出现此错误。我想使用嵌套表为每个学生添加每个学期和年份的平均笔记数 有人能帮我弄清楚吗 Create or Replace type lista_medii is table of number; Alter Table studenti Add medii lista_medii nested table medii store as value; Create or replace procedure populare_medii as lista_tmp lis

尝试运行此过程时出现此错误。我想使用嵌套表为每个学生添加每个学期和年份的平均笔记数

有人能帮我弄清楚吗


Create or Replace type lista_medii is table of number;
Alter Table studenti Add medii lista_medii nested table medii store as value;

Create or replace procedure populare_medii
as
    lista_tmp lista_medii := lista_medii();
begin
    For v_student in (Select *from studenti) LOOP

         For an in 1 .. v_student.AN LOOP
             For medii_student in (select avg(valoare)from note join CURSURI on note.ID_CURS=CURSURI.ID where CURSURI.AN=1 and note.ID_STUDENT=29 group by cursuri.SEMESTRU) LOOP
                    lista_tmp.extend();
                    lista_tmp(lista_tmp.COUNT) := medii_student;
                end loop;
             update STUDENTI set STUDENTI.medii=lista_tmp where studenti.ID=v_student.id;
                lista_tmp.delete();
             end loop;
        end loop;
end populare_medii;


一定是这样的:

For medii_student in (select avg(valoare) as avg_valoare from note join CURSURI on note.ID_CURS=CURSURI.ID where CURSURI.AN=1 and note.ID_STUDENT=29 group by cursuri.SEMESTRU) LOOP
      lista_tmp.extend();
      lista_tmp(lista_tmp.COUNT) := medii_student.avg_valoare ;
end loop;
或者更好:

select avg(valoare) 
BULK COLLECT INTO lista_tmp
from note 
   join CURSURI on note.ID_CURS=CURSURI.ID 
where CURSURI.AN=1 
   and note.ID_STUDENT=29 
group by cursuri.SEMESTRU
或者更好:

update STUDENTI set STUDENTI.medii =
(select avg(valoare) 
    from note 
       join CURSURI on note.ID_CURS=CURSURI.ID 
    where CURSURI.AN=1 
       and note.ID_STUDENT=29 
    group by cursuri.SEMESTRU)
where studenti.ID=v_student.id;
或者更好的做法是在一个更新语句中完成—自己尝试