DECLARE
TYPE T IS TABLE OF emp.sal%TYPE INDEX BY BINARY_INTEGER;
saltab T;
avg10 emp.sal%type;
FUNCTION avg_sal (maximum NUMBER DEFAULT 5000) RETURN T
IS
avgtab T;
BEGIN
avgtab(10):=0; -- Defaultwert falls kein Wert zurückkommt
FOR rec_avg IN (SELECT deptno,round(avg(sal),0) avgsal from emp
WHERE sal >= maximum group by deptno) loop
avgtab(rec_avg.deptno) := rec_avg.avgsal; -- Werte für Abt. 10, 20 und 30
END LOOP;
RETURN avgtab;
END;
BEGIN
saltab := avg_sal(1000);
saltab := avg_sal(6000); -- Kein Defaultwert
dbms_output.put_line(saltab(10));
avg10 := avg_sal(1000) (10); -- Average an der Stelle 10
--avg10 := avg_sal (10); --> Fehler falscher Typ!
END;
/