Oracle 12中的本地集合类型是否存在问题?

为了简短说明,我建议您讨论下面的代码.

运行时:

> Oracle 11编译器引发

“PLS-00306: wrong number or types of arguments tips in call to ‘PIPE_TABLE'”

“PLS-00642: Local Collection Types Not Allowed in sql Statement”

> Oracle 12编译下面的包,没有这样的警告,但我们在运行时有一个惊喜

when executing the anonymous block as is – everything is fine
(we may pipe some rows in the pipe_table function – it doesn’t affect)

Now let’s uncomment the line with hello; or put there a call to any procedure,and run the changed anonumous block again
we get “ORA-22163: left hand and right hand side collections are not of same type”

问题是:
Oracle 12是否允许sql中的本地集合类型?
如果是,那么PACKAGE buggy_report的代码有什么问题?

CREATE OR REPLACE PACKAGE buggy_report IS

  SUBTYPE t_id IS NUMBER(10);
  TYPE t_id_table IS TABLE OF t_id;

  TYPE t_info_rec IS RECORD ( first NUMBER );
  TYPE t_info_table IS TABLE OF t_info_rec;
  TYPE t_info_cur IS REF CURSOR RETURN t_info_rec;

  FUNCTION pipe_table(p t_id_table) RETURN t_info_table PIPELINED;

  FUNCTION get_cursor RETURN t_info_cur;

END buggy_report;
/

CREATE OR REPLACE PACKAGE BODY buggy_report IS

  FUNCTION pipe_table(p t_id_table) RETURN t_info_table PIPELINED IS
    l_table t_id_table;
    BEGIN
      l_table := p;
    END;

  FUNCTION get_cursor RETURN t_info_cur IS
    l_table  t_id_table;
    l_result t_info_cur;
    BEGIN

      OPEN l_result FOR SELECT * FROM TABLE (buggy_report.pipe_table(l_table));

      RETURN l_result;
    END;
END;
/

DECLARE
  l_cur buggy_report.t_info_cur;
  l_rec l_cur%rOWTYPE;
  PROCEDURE hello IS BEGIN NULL; END;
BEGIN

  l_cur := buggy_report.get_cursor();

  -- hello;

  LOOP
    FETCH l_cur INTO l_rec;
    EXIT WHEN l_cur%NOTFOUND;
  END LOOP;

  CLOSE l_cur;

  dbms_output.put_line('success');
END;
/
是的,在Oracle 12c中,您可以在sql中使用本地集合类型.

文档Database New Features Guide说:

PL/sql-Specific Data Types Allowed Across the PL/sql-to-sql Interface

The table operator can Now be used in a PL/sql program on a collection whose data type is declared in PL/sql. This also allows the data type to be a PL/sql associative array. (In prior releases,the collection’s data type had to be declared at the schema level.)

但是,我不知道你的代码为什么不工作,也许这个新功能还是有一个bug.

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...