无法从PLSQL表类型批量收集到表中?

时间:2015-05-28 08:16:10

标签: sql oracle stored-procedures plsql oracle11g

SELECT *   BULK COLLECT INTO CONNECT_RET_ITEM_DETAIL FROM TABLE(RET_ITEM_IN);

此处RET_ITEM_IN是表格类型RET_ITM_DTL_TMP;

的实例
desc RET_ITM_DTL_TMP;

-------------------------------- 
 TYPE RET_ITM_DTL_TMP AS   OBJECT   (
    ITEM_ID       VARCHAR2(50),
    ITEM_DESC     VARCHAR2(50),
    ORDER_NUMBER  VARCHAR2(50),
    PARCEL_NUMBER VARCHAR2(50),
    STORE_NUMBER  VARCHAR2(50),
    QUANTITY      NUMBER ) ;  


desc CONNECT_RET_ITEM_DETAIL

Name          Null Type         
------------- ---- ------------ 
 ITEM_ID            VARCHAR2(50) 
 ITEM_DESC          VARCHAR2(50)  
 ORDER_NUMBER       VARCHAR2(50)  
 PARCEL_NUMBER      VARCHAR2(50)  
 STORE_NUMBER       VARCHAR2(50)
 QUANTITY           NUMBER   

我可以在以下情况下成功批量收集:

  1. 对象
  2. 表格对象
  3. 表到表
  4. 但是在对象到表类型插入失败。得到以下错误:

      

    错误(118,6):PLS-00403:表达式'CONNECT_RET_ITEM_DETAIL'不能   用作SELECT / FETCH语句的INTO目标

1 个答案:

答案 0 :(得分:0)

不确定这是否完全解决了您的问题,但也许这段代码会很有用。像这样创建表:

create table CONNECT_RET_ITEM_DETAIL of RET_ITM_DTL_TMP;

接下来这个PL / SQL对我有用:

declare
  type RET_ITM_DTL_TBL is table of RET_ITM_DTL_TMP;
  RET_ITEM_IN RET_ITM_DTL_TBL;
begin
  RET_ITEM_IN := RET_ITM_DTL_TBL(
      RET_ITM_DTL_TMP ('a11', 'a12', 'a13', 'a14', 'a15', 11), 
      RET_ITM_DTL_TMP ('b11', 'b12', 'b13', 'b14', 'b15', 21),
      RET_ITM_DTL_TMP ('b21', 'b22', 'b23', 'b24', 'b25', 22) );

  FORALL i IN RET_ITEM_IN.first .. RET_ITEM_IN.last 
    INSERT INTO CONNECT_RET_ITEM_DETAIL VALUES RET_ITEM_IN(i);
end;