I created the following type:
CREATE OR REPLACE EDITIONABLE TYPE "MY_CUSTOM_TYPE" AS OBJECT ( my_num NUMBER, my_char VARCHAR2(3000) )
Inside of a procedure then I accept this parameter and want to loop through it:
create or replace PROCEDURE my_proc( P_MY_TYPE IN MY_CUSTOM_TYPE ) BEGIN FOR i IN P_MY_TYPE.FIRST .. P_MY_TYPE.LAST LOOP dbms_output.put_line( P_MY_TYPE(i).my_num || ' ' || P_MY_TYPE(i).my_char); END LOOP; END;
I keep getting this error though:
PLS-00302: component 'FIRST' must be declared
Advertisement
Answer
It is possible that you want to create a collection type
create type my_custom_collection as table of my_custom_type;
and then pass that collection to your procedure
create or replace procedure my_proc( p_collection my_custom_collection ) as begin for i in 1..p_collection.count loop dbms_output.put_line( p_collection(i).my_num || ' ' || p_collection(i).my_char ); end loop; end my_proc;
If that is not what you are looking for, please edit your question to explain what exactly you are trying to loop over. An object type is a scalar so it doesn’t make sense to try to call first
or last
on it or to try to access the ith element.