plsql - 将 plsql 嵌套表类型与另一个常规 sql 表连接
问题描述
我想使用常规 sql 从嵌套表类型中进行选择。
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
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;
我遇到一个错误说
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
我想将此表 l_invoices 与我的常规发票表一起加入。关于我该怎么做的任何想法?
解决方案
问题不在于您使用类型的方式,而在于您尝试从 Pl/SQL 块中执行选择查询而不将结果提取到任何变量中。
您的代码可能是:
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;
推荐阅读
- javascript - 如何允许输入输入字段编号 1、2 或 3
- typescript - Firebase 对 .doc().get() 的权限不足
- r - 如何在 geom_text 中使用上标?
- python - Flutter 没有收到来自 Flask REST API 的响应
- python - 从 tesseract 返回值中删除换行符 \n
- java - 如何在 Android 中使用 AsyncHttpClient 下载和读取 Excel 文件
- flutter - 如何在颤振中解析json
- python - TypeError: contact() got an unexpected keyword argument 'name' - 为什么我在 django 中得到这样的错误?
- spring - Repository.saveAll 抛出 InvalidDataAccessApiUsageException
- python - Liquid 和 Python:print(dir(numpy)) 但在 Liquid 中