0

i am new and trying to learn pl sql programming.

How can we insert data in 2D array using plsql program. i was able to insert data in 1D array, but i am facing problems for inserting data in 2D array.

declare
  type type1 is table of number;
  type data_type is table of type1;
  y data_type;
begin
  y := data_type();
  y.extend(20000);
  for i in 1..100 loop
    for j in 1..100 loop
      y(i)(j) := i+j; 
    end loop;
  end loop;
end;

any information or hint will be helpful.

1 Answer 1

1

You initialize and extend the outer array y, but you also need to initialize and extend each sub-array y(i):

declare
  type type1 is table of number;
  type data_type is table of type1;
  y data_type;
begin
  y := data_type();
  y.extend(100);
  for i in 1..100 loop
    y(i) := type1();
    y(i).extend(100);
    for j in 1..100 loop
      y(i)(j) := i+j; 
    end loop;
  end loop;
end;
/

The above code runs successfully on my Oracle XE 11gR2 database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.