I have been trying to return 2 values from a function in PL/SQL . The first value i want it to be the salary of the guy i have to search for. The second i want it to be the number of rows affected by this. I searched google for a while and i found out that i must first make a type so that i can return the data. However i get an error :
Error(9,1): PL/SQL: SQL Statement ignored
Error(9,36): PL/SQL: ORA-00936: missing expression
The code that i have is :
CREATE OR REPLACE TYPE return_type AS OBJECT(val1 NUMBER,val2 NUMBER);
CREATE OR REPLACE FUNCTION f2
(v_nume employees.last_name%TYPE DEFAULT 'Bell')
RETURN return_type IS
out_var return_type;
salariu employees.salary%type;
BEGIN
SELECT salary INTO salariu
FROM employees
WHERE last_name = v_nume;
INSERT INTO out_var values(salariu,@@ROWCOUNT);
RETURN out_var;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20000, 'Nu exista angajati cu numele dat');
WHEN TOO_MANY_ROWS THEN
RAISE_APPLICATION_ERROR(-20001, 'Exista mai multi angajati cu numele dat');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20002,'Alta eroare!');
END f2;
/
INSERT INTO out_var values(salariu,@@ROWCOUNT);with the assignment statementsout_var.val1 := salariu; out_var.val1 := 1;, you can't insert values into object, in case of pl/sql