gpt4 book ai didi

oracle - 如何从嵌套表中选择列值

转载 作者:行者123 更新时间:2023-12-02 09:30:10 30 4
gpt4 key购买 nike

我创建了 1 个对象。

create type tab_billing as object(invoice_no number, 
customername varchar2(100)
);

现在我创建了一个表,其中该对象作为列。

CREATE TABLE tab1 (col1 number,COL2 tab_billing);

无论如何,我只能从选项卡1中选择invoice_no

select col2 from tab1; 

给了我invoice_nocustomernameSubstr 函数在这里不起作用。

最佳答案

可以直接查询列值的对象字段,但要避免混淆 the object name resolution您必须提供和使用表别名的步骤:

select t1.col2.invoice_no from tab1 t1;

提到了这个in the documentation :

To avoid inner capture and similar problems resolving references, Oracle Database requires you to use a table alias to qualify any dot-notational reference to subprograms or attributes of objects.

仅用表名限定列是不够的;使用 select tab1.col2.invoice_no from tab1 得到 ORA-00904。您必须使用表别名 - 尽管有点奇怪,如果别名与表名称相同,它仍然有效,因此 select tab1.col2.invoice_no from tab1 tab1 (即别名 tab1 作为 tab1(通常是多余的)也可以工作。

快速演示:

create type tab_billing as object(invoice_no number, 
customername varchar2(100)
);
/

Type TAB_BILLING compiled

CREATE TABLE tab1 (col1 number,COL2 tab_billing);

Table TAB1 created.

insert into tab1 values (1, tab_billing(42, 'Test'));

1 row inserted.

select t1.col2.invoice_no from tab1 t1;

COL2.INVOICE_NO
---------------------------------------
42

关于oracle - 如何从嵌套表中选择列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38997436/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com