create or replace procedure salarycompall as
CURSOR empIDs IS SELECT employee_id from EMPLOYEES;
begin
FOR e in empIDs
LOOP
SALARYCOMP(e);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
end salarycompall;
This procedure should call another procedure SALARYCOMP. The SALARYCOMP expects the Datatype EMPLOYEES.EMPLOYEE_ID%type, but i get the errors Error(7,9): PL/SQL: Statement ignored and Error(7,9): PLS-00306: wrong number or types of arguments in call to 'SALARYCOMP'.
I have tried just printing out every e in empIDs but i get the same errors, so is there something wrong in my for loop?
Kind Regards
CodePudding user response:
Your cursor loop variable e
is a record, not a scalar value; you need to refer to the field within that record:
SALARYCOMP(e.employee_id);
To think about why you can't just pass e
, imagine your cursor query was:
SELECT employee_id, manager_id from EMPLOYEES
Then if you called SALARYCOMP(e)
you wouldn't just be passing the employee_id
it's expecting, you'd be passing both employee_id
and manager_id
; so then it's more obvious that're you're passing a record comprised of both values, and that you actually need to specify the field you meant, with SALARYCOMP(e.employee_id
).
With only one column in your cursor query it's perhaps a bit less obvious - but it's still the same mechanism, and isn't treated any differently. Calling SALARYCOMP(e)
still passes the whole record (with a single field).