Coat Coat - 7 months ago 23
SQL Question

Alias for a table of type?

I have the following definition for a table type

create table number_table as table of number;


And I'd like to use it like in the following example.

declare
l_myTable number_table := number_table(1, 2, 3);
begin
for i in (select * from l_myTable) loop
dbms_output.put_line(i.???); -- how do I reference the numbers here?
end loop;
end;


Forgive my code being somewhat pointless, how would I reference that
i.???
though to get the number out of the iterator?

Answer

Just slightly change your query to

select rownum, column_value from l_myTable

and then use dbms_output.put_line(i.rownum); as an index and dbms_output.put_line(i.column_value ); as a value

Comments