尝试使用BULK COLLECT
语句时,我收到错误ORA-00947: not enough values
。
示例脚本:
CREATE OR REPLACE
TYPE company_t AS OBJECT (
Company VARCHAR2(30),
ClientCnt INTEGER );
/
CREATE OR REPLACE
TYPE company_set AS TABLE OF company_t;
/
CREATE OR REPLACE
FUNCTION piped_set (
v_DateBegin IN DATE,
v_DateEnd IN DATE
)
return NUMBER /*company_set pipelined*/ as
v_buf company_t := company_t( NULL, NULL);
atReport company_set;
sql_stmt VARCHAR2(500) := '';
begin
select * BULK COLLECT INTO atReport
from (
SELECT 'Descr1', 1 from dual
UNION
SELECT 'Descr2', 2 from dual ) ;
return 1;
end;
错误发生在第select * BULK COLLECT INTO atReport
行。
直接PL / SQL顺便说一下(所以不需要提及它作为解决方案)。将BULK COLLECT
用于用户表类型是个问题。
答案 0 :(得分:9)
您的company_set
是对象的表格,您选择的是值,而不是由这些值组成的对象。这将编译:
select * BULK COLLECT INTO atReport
from (
SELECT company_t('Descr1', 1) from dual
UNION
SELECT company_t('Descr2', 2) from dual ) ;
...但是当运行时会抛出ORA-22950: cannot ORDER objects without MAP or ORDER method
,因为union
执行隐式排序以识别和删除重复项,因此请改用union all
:
select * BULK COLLECT INTO atReport
from (
SELECT company_t('Descr1', 1) from dual
UNION ALL
SELECT company_t('Descr2', 2) from dual ) ;