0

我有以下 PL/SQL 包:

CREATE OR REPLACE PACKAGE PKG_JCSJ
AS      
TYPE  record_organ_cant  IS RECORD(CANT_CODE VARCHAR2(90),
        ORGAN_ID  VARCHAR2(90) ,
        CANT_NAME VARCHAR2(90),
        SUPP_TYPE VARCHAR2(20));

  --TYPE array_organ_cant IS TABLE of PKG_JCSJ.record_organ_cant;
  TYPE array_organ_cant IS TABLE of pub_organ_cant%ROWTYPE;

  function fn_transe_organ_cant return PKG_JCSJ.array_organ_cant PIPELINED;
 END PKG_JCSJ;

create or replace package body PKG_JCSJ is

function fn_transe_organ_cant return PKG_JCSJ.array_organ_cant PIPELINED
as
   cursor cursor_organ_cant is select * from pub_organ_cant ; 
   record_o_c pub_organ_cant%rowtype; 
   record_o_c2 pub_organ_cant%rowtype;        
   cant_code VARCHAR2(90); 

   TYPE ref_cursor IS REF CURSOR; 
   array_column_value ref_cursor;  
   sp_cant_code VARCHAR2(90); 

begin
   open cursor_organ_cant;
   loop
        fetch cursor_organ_cant into record_o_c;
        exit when cursor_organ_cant%notfound;
        cant_code := record_o_c.cant_code;
        if instr(cant_code, ',')>0 then
           open array_column_value for select * from  table(fn_split(cant_code));
           loop
                fetch array_column_value into sp_cant_code;
                exit when array_column_value%notfound;
                --DBMS_OUTPUT.put_line('---' || sp_cant_code);
                record_o_c2.CANT_CODE := sp_cant_code;
                record_o_c2.ORGAN_ID := record_o_c.ORGAN_ID;
                record_o_c2.CANT_NAME := record_o_c.CANT_NAME;
                record_o_c2.SUPP_TYPE := record_o_c.SUPP_TYPE;
                --DBMS_OUTPUT.put_line('++++++' || record_o_c2.CANT_CODE);

                PIPE ROW (record_o_c2);
           end loop;
           close array_column_value;
        else   
           PIPE ROW (record_o_c);
        end if;
   end loop;
   close cursor_organ_cant;
   return;
end fn_transe_organ_cant;
begin
   null;
end PKG_JCSJ;

为什么这个声明失败了?

TYPE array_organ_cant IS TABLE of PKG_JCSJ.record_organ_cant;

错误信息是ORA-06502: PL/SQL: numeric or value error。但是,当我使用下面的语句时,成功了!

TYPE array_organ_cant IS TABLE of pub_organ_cant%ROWTYPE;

record_organ_cant与 TABLE 结构相同pub_organ_cant,我不知道为什么前者失败而后者成功,有什么区别?

然后,包装体如下,

4

1 回答 1

0

首先,在你的包体中你不必使用它,PKG_JCSJ.因为它在 pacakge 中声明并且应该可以被它的任何函数访问,比如

create or replace package body PKG_JCSJ is
function fn_transe_organ_cant return array_organ_cant PIPELINED
....

接下来,当您再次声明时,您不需要PKG_JCSJ.

CREATE OR REPLACE PACKAGE PKG_JCSJ
AS      
  TYPE  record_organ_cant  IS RECORD(CANT_CODE VARCHAR2(90),
        ORGAN_ID  VARCHAR2(90) ,
        CANT_NAME VARCHAR2(90),
        SUPP_TYPE VARCHAR2(20));

  TYPE array_organ_cant IS TABLE of record_organ_cant;

  function fn_transe_organ_cant return array_organ_cant PIPELINED;
 END PKG_JCSJ;
于 2012-08-09T04:28:16.743 回答