CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR(20);
IS
e_name VARCHAR(20);
BEGIN
SELECT emp_name INTO e_name
FROM employees WHERE emp_no = '5';
RETURN e_name;
END employer_details_func;
While compiling the above program I'm getting this error
Error(2,18): PLS-00103: Encountered the symbol "(" when expecting one of the following: . @ % ; is authid as cluster order using external character deterministic parallel_enable pipelined aggregate result_cache
UPDATE:
CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR2(20);
IS
e_name VARCHAR2(20);
BEGIN
SELECT emp_name INTO e_name FROM employees WHERE emp_no ='5';
RETURN e_name;
END employer_details_func;
Error:
Error(2,19): PLS-00103: Encountered the symbol "(" when expecting one of the following: . @ % ; is authid as cluster order using external character deterministic parallel_enable pipelined aggregate result_cache
What is wrong with my code? Please let me know.
return varchar(20)should be simplyreturn varchar2. Do not usevarchardata type. Althoughvarcharandvarchar2are synonymous and there is no difference between them right now, their behavior may change in the future - stick tovarchar2. Moreover take into consideration the fact that your query may return no rows, or return more than one row, raisingno_data_foundortoo_many_rowsexception respectively.return ...- remove it. Otherwise your function should compile just fine.