SET SERVEROUTPUT ON
DECLARE
  mennyiseg INTEGER;
  median EMP.sal%TYPE;
  i INTEGER := 0;
BEGIN
  SELECT COUNT(*) INTO mennyiseg FROM emp;
    FOR rek IN (SELECT * FROM EMP ORDER BY sal ASC)
    LOOP
      i := i + 1;
      IF (MOD(mennyiseg, 2) = 1) AND (i = mennyiseg / 2) THEN
        DBMS_OUTPUT.PUT_LINE(rek.sal);
        EXIT;
      ELSIF (MOD(mennyiseg, 2) = 0) AND (i = mennyiseg / 2) THEN
        median := rek.sal;
      ELSIF (MOD(mennyiseg, 2) = 0) AND (i = (mennyiseg / 2) + 1) THEN
        median := (median + rek.sal) / 2;
        DBMS_OUTPUT.PUT_LINE(median);
        EXIT;
      END IF;
    END LOOP;
END;