Skip to Main Content
  • Questions
  • 1000 Column Limit populating a collection (ORA-00939)

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, vamsi.

Asked: July 11, 2017 - 7:59 pm UTC

Last updated: July 16, 2017 - 7:17 am UTC

Version: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit

Viewed 1000+ times

You Asked

Hi,

I have a need to work with a collection of composite data type with more than 1000 columns in it.

Here is the sample code below for collection with composite data type of 2 columns.

CREATE OR REPLACE TYPE obj_typ1 AS OBJECT (col1 number, col2 NUMBER);

CREATE OR REPLACE TYPE col_typ1 AS table OF obj_typ1;


DECLARE
var_typ col_typ1;
BEGIN
  SELECT obj_typ1(1,2) INTO var_typ FROM (SELECT 1,2 from dual);
END; 


When I increase the number to more than 1000 I get a ORA-00939: too many arguments for function ERROR

CREATE OR REPLACE TYPE obj_typ1 AS OBJECT (col1 number, col2 NUMBER......... col1000 NUMBER);

CREATE OR REPLACE TYPE col_typ1 AS table OF obj_typ1;


DECLARE
var_typ col_typ1;
BEGIN
  SELECT obj_typ1(1,2.....1000) INTO var_typ FROM dual;
END; 


A select list can contain more than 1000 columns and an Object Type can contain more than 1000 columns, but I am not able to populate that collection from the Select statement when the count is more than 1000 for the column list.

Is there a work around for this?

Thanks!

with LiveSQL Test Case:

and Chris said...

This is a documented limit for constructor functions:

In an invocation of a type constructor method, the number of parameters (expr) specified cannot exceed 999, even if the object type has more than 999 attributes. This limitation applies only when the constructor is called from SQL. For calls from PL/SQL, the PL/SQL limitations apply.

http://docs.oracle.com/database/122/SQLRF/Type-Constructor-Expressions.htm#SQLRF52094

This limit is in SQL. In PL/SQL you can go higher. So you can overcome this by initializing it outside a SQL statement, e.g.:

DECLARE
  var_typ col_typ;
BEGIN
  var_typ := col_typ(obj_typ(1,2,...,999,1000));
END;
/

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

vamsi avala, July 14, 2017 - 8:25 pm UTC

Thank you for your response.

I have a data set in the form of a Select Statement with more than 1000 columns in it. I am looking at options to get it into memory (hence the original question). Please let me know on any pointers you have on the direction I could take in getting that done.


Thank!
Connor McDonald
July 16, 2017 - 7:17 am UTC

Consider using associative arrays rather than nested tables ? For example, this works fine

declare
  cursor c is
select 1 c1,
1 c2,
1 c3,
1 c4,
1 c5,
1 c6,
...
...
...
1 c1999,
1 c2000
from dual;

type t is table of c%rowtype index by pls_integer;
r t;
begin
  open c; fetch c bulk collect into r; close c;
end;
/



More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library