如何 select 一个对象的字段是 table 的字段?
How to select the a field of an object being a field of a table?
测试代码:https://dbfiddle.uk/?rdbms=oracle_21&fiddle=8cf685ff21a69c5e83a9861a56a71cbb
我有一个table。它的字段之一是一个对象。我只想select这个对象的一个字段。
create type a as object(
a integer
)
-- I have succeeded to select the object
with b(c) as (select a(2) from dual) select c from b
--but I have failed to only select the field of this object
with b(c) as (select a(2) from dual) select c.a from b
ORA-00904: "C"."A": invalid identifier
给子查询一个别名,然后引用别名:
with b(c) as (
select a(2) from dual
)
select b.c.a
from b b
注意:是的,我给它取了与 table 名称相同的别名。给它一个不同的别名可能不会那么混乱,但重要的是使用别名然后将其称为 <table_alias>.<column_identifier>.<attribute_identifier>
.
输出:
C.A
2
db<>fiddle here
测试代码:https://dbfiddle.uk/?rdbms=oracle_21&fiddle=8cf685ff21a69c5e83a9861a56a71cbb
我有一个table。它的字段之一是一个对象。我只想select这个对象的一个字段。
create type a as object(
a integer
)
-- I have succeeded to select the object
with b(c) as (select a(2) from dual) select c from b
--but I have failed to only select the field of this object
with b(c) as (select a(2) from dual) select c.a from b
ORA-00904: "C"."A": invalid identifier
给子查询一个别名,然后引用别名:
with b(c) as (
select a(2) from dual
)
select b.c.a
from b b
注意:是的,我给它取了与 table 名称相同的别名。给它一个不同的别名可能不会那么混乱,但重要的是使用别名然后将其称为 <table_alias>.<column_identifier>.<attribute_identifier>
.
输出:
C.A 2
db<>fiddle here