Vytaus
Vytaus

Reputation: 27

PLS-00306: wrong number or types of arguments in call to 'OUTPUT_ARRAY'

I'm stuck with this error and really don't know how to fix it. Maybe i'm passing array in improper way?

This is main sql file.

DECLARE
  v_array_length NUMBER := &v_array_length;
BEGIN
  DECLARE
    TYPE number_array_type IS TABLE OF NUMBER(6, 2) INDEX BY BINARY_INTEGER;
    v_array NUMBER_ARRAY_TYPE;
  BEGIN
    --Isvediams
    IOPACKAGE.OUTPUT_MESSAGE('Original array:');
    --Sugeneruoja atsitiktinius array elementus is intervalo [1, 1000]
    FOR i IN 1..v_array_length LOOP
            v_array(i) := SYS.DBMS_RANDOM.VALUE(1, 1000);
          END LOOP;
    IOPACKAGE.OUTPUT_ARRAY(v_array);
  END;
END;

This is IOpackage sql file

CREATE OR REPLACE PACKAGE IOpackage IS
  l_message VARCHAR2(100);
  PROCEDURE output_message(l_message IN VARCHAR2);
  TYPE number_array_type IS TABLE OF NUMBER(6, 2) INDEX BY BINARY_INTEGER;
  PROCEDURE output_array(v_array NUMBER_ARRAY_TYPE);
END IOpackage;

and this is IOpackage_body file.

CREATE OR REPLACE PACKAGE BODY IOpackage IS
  PROCEDURE output_message(l_message IN VARCHAR2) IS
  BEGIN
    DBMS_OUTPUT.PUT_LINE(l_message);
  END output_message;
  PROCEDURE output_array(v_array IN NUMBER_ARRAY_TYPE) IS
  BEGIN
    FOR i IN 1..v_array.COUNT LOOP
              DBMS_OUTPUT.PUT(v_array(i) || ' ');
            END LOOP;
    DBMS_OUTPUT.PUT_LINE('');
  END output_array;
END IOpackage;

Upvotes: 1

Views: 2693

Answers (1)

user272735
user272735

Reputation: 10648

The type definition in main sql file is not the type that is expected by the package subroutine. IOPACKAGE.OUTPUT_ARRAY-subroutine expects type IOPACKAGE.NUMBER_ARRAY_TYPE. You don't have to re-define the type. The following should work:

declare
  v_array IOPACKAGE.NUMBER_ARRAY_TYPE;
begin
  IOPACKAGE.OUTPUT_ARRAY(v_array);
end;

See the difference between IOPACKAGE.NUMBER_ARRAY_TYPE and NUMBER_ARRAY_TYPE. They are similar but not the same.

Upvotes: 2

Related Questions