Search code examples
oracle-databaseplsqlplsqldeveloper

Unknown reason for PLS-00306: wrong number or types of arguments


I'm having a problem with simple PL/SQL here. I defined my table as follows:

TYPE tr_GatheredData IS RECORD(
BS_ID          number,
CUSTOMER_NAME  varchar2(200),
MONTH          varchar2(30),
YEAR           number,
LEAKAGE        number);

TYPE tt_GatheredData IS TABLE OF tr_GatheredData;

Afterwards I try to initiate a variable like this:

results := tt_GatheredData(1, 'lol', 'omg', 2, 3);

Everything seams to me to be correct, but I get

Error(8,16): PLS-00306: wrong number or types of arguments in call to 'TT_GATHEREDDATA'

on each compliation. Can you guys tell me where can the issiue be?


Solution

  • Oracle 18c qualified expression:

    DECLARE
      TYPE tr_GatheredData IS RECORD(
         BS_ID          number,
         CUSTOMER_NAME  varchar2(200),
         MONTH          varchar2(30),
         YEAR           number,
         LEAKAGE        number);
    
      TYPE tt_GatheredData IS TABLE OF tr_GatheredData;
      results tt_GatheredData;
    BEGIN
       results := tt_GatheredData(tr_GatheredData(1, 'lol', 'omg', 2, 3));
       DBMS_OUTPUT.PUT_LINE(results(1).Customer_name);
    END;
    //
    

    Previous versions:

    DECLARE
    TYPE tr_GatheredData IS RECORD(
    BS_ID          number,
    CUSTOMER_NAME  varchar2(200),
    MONTH          varchar2(30),
    YEAR           number,
    LEAKAGE        number);
    TYPE tt_GatheredData IS TABLE OF tr_GatheredData;
      results tt_GatheredData;
      t tr_GatheredData ;
    BEGIN
       t.BS_ID := 1;
       t.CUSTOMER_NAME := 'lol';
       t.MONTH := 'omg';
       t.YEAR := 2;
       t.LEAKAGE := 3;
       results := tt_GatheredData(t);  -- element has to be record type
    
       DBMS_OUTPUT.PUT_LINE(results(1).Customer_name);
    END;
    //
    

    db<>fiddle demo