在 SELECT FROM TABLE(collection) 中为全局集合类型的匿名列指定别名

Give alias to anonymous column of global collection type in SELECT FROM TABLE(collection)

我正在尝试在 SELECT 查询中使用 apex_t_numbers 集合中的值作为 WITH 子查询:

atn_cur_ids := apex_string.split_numbers(arg_v_ids, ':');
-- So if arg_v_ids := '1:2:3', then atn_cur_ids := apex_t_numbers(1, 2, 3)

with t_cur_ids as (
  select * as id from table(atn_cur_ids);
)
select text from t_texts 
join t_cur_ids on t_texts.id = t_cur_ids.id

这就是问题所在 - apex_t_numbersnumber 的 table,而不是具有命名字段的 record 类型。 Oracle SQL 不允许为 * 提供别名,即使它只有一个 "anonymous" 列。

一个可能的解决方案可以是一个函数,

  1. 收到*
  2. return每行值

但我知道只有一个可以得到 * 和 return 东西 - count(*),它不符合第二个要求。

好的,找到解决办法了。可以使用 column_value 作为列的名称来完成:

with t_cur_ids as (
  select column_value as id from table(atn_cur_ids);
)
select text from t_texts 
join t_cur_ids on t_texts.id = t_cur_ids.id