plsql - PLSQL - 返回代码集合
问题描述
我正在尝试编写一个函数来返回代码列表。
在我声明的包装规格中
type codes_t is table of number;
和
function getCodes(
acc_id in Account.id%type
)
return codes_t;
在我的身体里
function getCodes(
acc_id in Account.id%type
)
return codes_t
is
v_codes codes_t := codes_t();
begin
for row in (select ...) loop
v_codes.extend();
v_codes(v_codes.count) := row.code;
end loop;
return codes_t;
包编译器没有错误,但是当我尝试调用函数时
select pkg.getCodes(123) from dual;
我得到ORA-00902: 无效的数据类型
有什么明显的错误吗?
解决方案
或者它可以是流水线的。 演示
CREATE OR REPLACE PACKAGE pkg
is
type codes_t is table of number;
function getCodes(
acc_id in NUMBER
)
return codes_t PIPELINED;
end pkg;
/
CREATE OR REPLACE PACKAGE BODY pkg
is
function getCodes(
acc_id in NUMBER
) return codes_t PIPELINED
is
v_codes codes_t := codes_t();
begin
for r in (select acc_id as code from dual
union
select acc_id+1 from dual) loop
PIPE row(r.code);
end loop;
end getCodes;
end pkg;
/
推荐阅读
- javascript - 如何在录制停止后立即显示录制的长度和下载选项?
- python - 如何使用 python selenium 单击 Hcaptcha 复选框
- java - Spring Boot @Getmapping 在一个非常简单的项目中返回 404 whitelabel 错误页面
- sql-server - ER 模型可以包含相同的关系集命名吗?实体集中的列名是否应该与 sql-server 表中的相同?
- flutter - 使用块重建堆栈内的小部件?
- javascript - scrollToIndex 在本机反应中超出范围
- python-3.x - 打印列表中的条目及其在列表中的次数
- c++ - 我是 OOP 的新手,正在努力解决一个基本的继承错误:“{”标记之前的预期类名
- python - 当我打印(*args)时会发生什么(注意星号*)
- flutter - 颤振:获取画廊图像以显示在刷卡中