ORA-00932:不一致的数据类型应为UDT GET数字

qxsslcnc  于 2022-10-04  发布在  Oracle
关注(0)|答案(1)|浏览(283)

有谁能帮忙吗。我已经把这件事简化了,但想不出来。我得到ORA-00932:不一致的数据类型预期UDT得到编号。我已经花了一周的时间来弄清楚这一点。我对此没有太多经验。

create or replace TYPE            TEST_REC as object (
    NUM NUMBER
);

create or replace TYPE            TEST_TAB is table of ELIMINATOR.TEST_REC

create or replace FUNCTION            test_func_smm return TEST_TAB
as
        query_str_main             VARCHAR2 (20000);
        V_ILIMIT                   NUMBER ;  
        V_IINTCNT                  PLS_INTEGER := 0;

      TYPE RC IS REF CURSOR;

      VRC        RC;
      VTAB        TEST_TAB := TEST_TAB ();
      VTEMPTAB    TEST_TAB := TEST_TAB ();

      con_iReclimit CONSTANT   NUMBER := 5000;

begin

query_str_main := ' select 5 as a from dual';

      dbms_output.put_line(query_str_main);

      OPEN VRC FOR query_str_main;

      LOOP
         EXIT WHEN VRC%NOTFOUND;

         FETCH VRC
            BULK COLLECT INTO   VTEMPTAB
            LIMIT con_iReclimit;
            DBMS_OUTPUT.PUT_LINE('BULK COLLECT');

     VTAB :=
     VTAB MULTISET UNION ALL VTEMPTAB;

     V_IINTCNT :=  
     V_IINTCNT + VTEMPTAB.COUNT;

      END LOOP;

      IF VRC%ISOPEN
         THEN
            CLOSE VRC;
         END IF;

      RETURN VTAB;
end;
r1zk6ea1

r1zk6ea11#

这就是罪魁祸首:

query_str_main := ' select 5 as a from dual';

应该是

query_str_main := ' select test_rec(5) as a from dual';

固定时,函数起作用

SQL> CREATE OR REPLACE FUNCTION test_func_smm
  2     RETURN test_tab
  3  AS
  4     query_str_main          VARCHAR2 (20000);
  5     v_ilimit                NUMBER;
  6     v_iintcnt               PLS_INTEGER := 0;
  7
  8     TYPE rc IS REF CURSOR;
  9
 10     vrc                     rc;
 11     vtab                    test_tab := test_tab ();
 12     vtemptab                test_tab := test_tab ();
 13
 14     con_ireclimit  CONSTANT NUMBER := 5000;
 15  BEGIN
 16     query_str_main := ' select test_rec(5) as a from dual';
 17
 18     DBMS_OUTPUT.put_line (query_str_main);
 19
 20     OPEN vrc FOR query_str_main;
 21
 22     LOOP
 23        EXIT WHEN vrc%NOTFOUND;
 24
 25        FETCH vrc BULK COLLECT INTO vtemptab LIMIT con_ireclimit;
 26
 27        DBMS_OUTPUT.put_line ('BULK COLLECT');
 28
 29        vtab := vtab MULTISET UNION ALL vtemptab;
 30
 31        v_iintcnt := v_iintcnt + vtemptab.COUNT;
 32     END LOOP;
 33
 34     IF vrc%ISOPEN
 35     THEN
 36        CLOSE vrc;
 37     END IF;
 38
 39     RETURN vtab;
 40  END;
 41  /

Function created.

测试:

SQL> SELECT * FROM TABLE (test_func_smm);

       NUM
----------
         5

select test_rec(5) as a from dual
BULK COLLECT
SQL>

相关问题