Как обращаться к столбцам коллекций скалярных типов внутри table()?
Предположим, у нас есть результат преобразования в таблицу.
Как обращаться к столбцам в такой таблице?
declare
a t_numbers;
c t_numbers;
begin
select * bulk collect into a from (select 1 d from dual union all select 2 d from dual);
select * bulk collect into c from table(a) a1 where a1.??? = 2;
------^^^
FOR i IN 1..c.COUNT LOOP
DBMS_OUTPUT.PUT_LINE(c(i));
END LOOP;
end;
Ответы (1 шт):
Автор решения: 0xdb
→ Ссылка
[...] or when you use the TABLE collection expression to refer to a scalar nested table type, the database returns a virtual table with a single column.
This name of this pseudocolumn isCOLUMN_VALUE.
У колллекций скалярных типов всегда один псевдостолбец, его имя - COLUMN_VALUE.
create or replace type t_numbers is table of number
/
declare
a t_numbers;
c t_numbers;
begin
select * bulk collect into a from (
select 1 d from dual union all
select 2 d from dual);
select * bulk collect into c
from table(a) a1
where a1.column_value = 2;
for i in 1..c.count loop
dbms_output.put_line ('value('||i||')='||c(i));
end loop;
end;
/
value(1)=2