Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

For loop PLSQL Statement Ignored

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading