Below is the code which I've used to store the values in a varray and finally return the varray. But I'm encountering an error at line 12 saying "Line/Col: 12/8 PLS-00103: Encountered the symbol "EMP_TYPE" when expecting one of the following: := . ( @ % ;" What improvements do I need to make?

create or replace type emp_type AS VARRAY(25) OF VARCHAR(10);
/

create or replace function emp_sal
return emp_type
is 
  emp emp_type := emp_type();
  l_salary number(10);
  maxim number(10);
  minim number(10);
BEGIN
   SELECT sum(salary) INTO l_salary FROM Employee8_43;
   SELECT max(salary) INTO maxim FROM Employee8_43;
   SELECT min(salary) INTO minim FROM Employee8_43;
   emp emp_type := emp_type(l_salary,maxim,minim);
  return emp;
END;
1

There are 1 best solutions below

1
On

You're quite close; shame you didn't read what Oracle has told you.

Line/Col: 12/8 PLS-00103: Encountered the symbol "EMP_TYPE" when expecting ...

It tells literally everything you need to know: line number, column number, and what it found but expected something else.

This:

emp emp_type := emp_type(l_salary,maxim,minim);

should be

emp          := emp_type(l_salary,maxim,minim);

So:

SQL> create or replace type emp_type as varray(25) of varchar(10);
  2  /

Type created.

SQL> create or replace function emp_sal
  2  return emp_type
  3  is
  4    emp emp_type := emp_type();
  5    l_salary number(10);
  6    maxim number(10);
  7    minim number(10);
  8  begin
  9     select sum(salary) into l_salary from employee8_43;
 10     select max(salary) into maxim from employee8_43;
 11     select min(salary) into minim from employee8_43;
 12     emp := emp_type(l_salary,maxim,minim);                --> this is line #12
 13    return emp;
 14  end;
 15  /

Function created.

SQL> select emp_sal from dual;

EMP_SAL
-------------------------------------------------------------------------
EMP_TYPE('29025', '5000', '800')

SQL>