【发布时间】:2021-11-21 10:42:58
【问题描述】:
我正在看书Practical Oracle SQL。在本书第 2 章中,作者正在创建一个具有用户定义类型的视图。以下是查询
create or replace type id_name_type as object (
id integer,
name varchar2(20 char)
);
/
create or replace type id_name_coll_type as table of id_name_type;
/
create or replace view customer_order_products_obj
as
select
customer_id,
max(customer_name) as customer_name,
cast(
collect(
id_name_type(product_id, product_name)
order by product_id
) as id_name_coll_type
) as product_coll
from customer_order_products
group by customer_id, id_name_coll_type;
但是当我尝试运行视图查询时,我收到了错误ORA-00904: "ID_NAME_COLL_TYPE": invalid identifier 然后我缩小了查询范围,只运行以下查询。只需运行 select 并从 group by 中删除名称。
select
customer_id,
max(customer_name) as customer_name,
cast(
collect(
id_name_type(product_id, product_name)
order by product_id
) as id_name_coll_type
) as product_coll
from customer_order_products
group by customer_id;
以上查询给出以下结果
那么group by customer_id, id_name_coll_type; 有什么问题?为什么在这种情况下我得到 "ID_NAME_COLL_TYPE": invalid identifier。因为它是一本书的例子,所以我认为它应该按原样工作?视图将如何创建?
谢谢
【问题讨论】:
标签: oracle oracle-sqldeveloper