2

I have a type like

CREATE OR REPLACE TYPE MY_TYPE AS OBJECT
(
  id               NUMBER(10, 0),
  name             VARCHAR2(4),
  lastName         VARCHAR2(13),
  address          VARCHAR2(30),
  previousAddress  VARCHAR2(80)
);

and a table of these as

CREATE OR REPLACE TYPE MY_TYPE_ROWS AS TABLE OF MY_TYPE

what I want to do is insert some rows that are returned from a cursor in this "MY_TYPE_ROWS" table. (and i want to do that in a pl/sql procedure)

The data that I want to insert into "MY_TYPE_ROWS" are in a cursor like:

cursor dataCursor IS 
select 
id,name, lastName,address,previousAddress
from table1;

(cursor returns more than 1 row)

I've tried something like:

 my_table_rows           MY_TYPE_ROWS := MY_TYPE_ROWS ();

  OPEN dataCursor ;
  FETCH dataCursor 
  INTO my_table_rows;
  CLOSE dataCursor ;

but i am getting an exception "Error: PLS-00386: type mismatch found at 'my_table_rows' between FETCH cursor and INTO variables"

thanks

1 Answer 1

1

Can't you do like that?

declare
  my_table_rows           my_type_rows;
begin
  select my_type(id,name,lastname,address,previousaddress)
  bulk collect into my_table_rows
  from table1;

  -- do whatever you want
end;

The problem of your method is that you are trying to select one row by single into which even does not contain any object.

And by definition it should be an array of objects. So bulk collect implements array fetching, and my_type(id,name,lastname,address,previousaddress) implements creating the objects of the array.

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.