Skip to Main Content
  • Questions
  • Why doesn't LIMIT collection method work on Associative Array Index by String

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Es.

Asked: September 26, 2024 - 5:39 pm UTC

Last updated: October 04, 2024 - 4:56 am UTC

Version: 23ai

Viewed 1000+ times

You Asked

Hi Tom,

Need your help. I searched about the error but couldn't find anything about it.

Below is the snippet from Oracle's Database PL/SQL Language Reference:
"LIMIT is a function that returns the maximum number of elements that the collection can have. If the collection has no maximum number of elements, LIMIT returns NULL. Only a varray has a maximum size."

Test code: In the following code block, the LIMIT collection method works only when "typ_associative_array" is INDEX BY PLS_INTEGER (or BINARY_INTEGER) but doesn't when INDEX BY <string-data-type> say VARCHAR2(10) or STRING(10).

DECLARE
    TYPE typ_associative_array IS TABLE OF DATE INDEX BY VARCHAR2(10);    
    v_typ_associative_array typ_associative_array;
BEGIN
    DBMS_OUTPUT.PUT_LINE(NVL(TO_CHAR(v_typ_associative_array.LIMIT),'Collection''s limit is Undefined'));
END;
/


Output:
Error report -
ORA-06550: line 5, column 62:
PLS-00306: wrong number or types of arguments in call to 'LIMIT'
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.

and Connor said...

I'd say that is a documentation bug that shows the history of the LIMIT function.

I had to go all the way back to the 8i documentation to see that the LIMIT function exists, but INDEX BY VARCHAR2 did *not* exist, and thus the text was valid. I suspect INDEX BY VARCHAR2 came along and no-one updated the docs to reflect that LIMIT did not apply.

I'll log a doc bug

Rating

  (2 ratings)

Comments

Is it a documentation bug or an implementation bug?

mathguy, September 30, 2024 - 4:15 pm UTC

If the LIMIT method is needed (and it probably is or else it wouldn't have been created), and it is supposed to return NULL for an associative array indexed by pls_integer, there is no reason it shouldn't also "work" (returning NULL) if the associative array is indexed by strings. The cure isn't to change the documentation, but to implement LIMIT for a.a. indexed by string (to return NULL as there is no maximum number of elements to an a.a., regardless of what it is indexed by).
Connor McDonald
October 04, 2024 - 4:51 am UTC

I would hypothesise that the term "never implemented" is probably the more appropriate here

Seems an implementation bug

Es, October 01, 2024 - 4:07 pm UTC

First of all, Thank You Connor for looking into it. But, I would disagree that it's a doc bug. Documentation seems pretty correct to me.

I wonder what could the possible logical explanation be given in documentation for not supporting LIMIT on Associative Array INDEX BY string?
Connor McDonald
October 04, 2024 - 4:56 am UTC

My guess is - never implemented.

More to Explore

DBMS_OUTPUT

More on PL/SQL routine DBMS_OUTPUT here