Is it possible to iterate over a cursor without the need for an intermediate TABLE as type of Object?
I have the following EVENT_TABLE setup in my schema
create TABLE EVENT_TABLE (
UUID INTEGER,
EVENT_TYPE VARCHAR2(10)
);
INSERT INTO EVENT_TABLE values( 1, 'START');
INSERT INTO EVENT_TABLE values( 2, 'RUNNING');
INSERT INTO EVENT_TABLE values( 2, 'COMPLETE');
CREATE OR REPLACE TYPE EVENT_OBJ AS OBJECT (
UUID INTEGER,
EVENT_TYPE VARCHAR2(10)
);
/
COMMIT;
declare
r EVENT_OBJ;
TYPE cur_typ IS REF CURSOR;
EVENT cur_typ;
BEGIN
OPEN event FOR 'select * from EVENT_TABLE';
LOOP
FETCH event INTO r;
EXIT WHEN event%NOTFOUND;
DBMS_OUTPUT.put_line('NEW_UID:-' || R.UUID);
END LOOP;
END;
/
when I execute the anonymous block at the end I get the following exception
ORA-00932 inconsistent datatypes: expected - got -
I've seen examples where a query is fetched into an object before but I can't seem to get it to work.
By creating a temporary table as follows, the anonymous block completes and the DBMS output as expected is produced?
declare
r EVENT_OBJ;
TYPE cur_typ IS REF CURSOR;
EVENT cur_typ;
-- Temp table
TYPE EVENT_TBL IS TABLE OF EVENT_OBJ;
lt_evt_tbl EVENT_TBL;
BEGIN
select EVENT_OBJ (UUID,EVENT_TYPE ) bulk collect into lt_evt_tbl from EVENT_TABLE;
FOR indx IN 1..lt_evt_tbl.COUNT
LOOP
DBMS_OUTPUT.put_line('NEW_UID:-' || lt_evt_tbl(indx).UUID);
END LOOP;
END;
/