首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将plsql嵌套表类型与另一个正则sql表连接起来。

将plsql嵌套表类型与另一个正则sql表连接起来。
EN

Stack Overflow用户
提问于 2021-02-25 21:18:54
回答 1查看 23关注 0票数 0

我想使用常规sql从嵌套表类型中进行选择。

代码语言:javascript
复制
create table invoices(invoice_id number);
insert into invoices values(100);
insert into invoices values(200);
insert into invoices values(300);
insert into invoices values(500);
create or replace type invoice_obt
as object (
invoice_id number
);
/

create type invoices_ntt
as table of invoice_obt;
/

下面是我的plsql

代码语言:javascript
复制
declare                                                        
l_invoices invoices_ntt := invoices_ntt();                     
begin                                                          
l_invoices.extend(3);                                          
l_invoices(1) := invoice_obt(100);                             
l_invoices(2) := invoice_obt(200);                             
l_invoices(3) := invoice_obt(200);                          
select invoice_id from invoices where invoice_id in (select * from table(l_invoices));                                
end;

我遇到了一个错误

代码语言:javascript
复制
select invoice_id from table(l_invoices);
*
ERROR at line 8:
ORA-06550: line 8, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement

我想加入这张桌子_发票与我的常规发票表。我该怎么做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-25 21:27:38

问题不在于您使用类型的方式,而在于您试图从Pl/SQL块中执行select查询,而不是将结果提取到任何变量中。

你的代码可以是:

代码语言:javascript
复制
DECLARE
    l_invoices   invoices_ntt := invoices_ntt ();

    /* define a variable to host the result of the query */
    TYPE tIdList IS TABLE OF NUMBER;
    vIdList      tIdList;
BEGIN
    l_invoices.EXTEND (3);
    l_invoices (1) := invoice_obt (100);
    l_invoices (2) := invoice_obt (200);
    l_invoices (3) := invoice_obt (200);

    SELECT invoice_id
      BULK COLLECT INTO vIdList  /* BULK COLLECT because you can have more than one row */
      FROM invoices
     WHERE invoice_id IN (SELECT * FROM TABLE (l_invoices));
END;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66369287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档