【问题标题】:ORA-22905 on setting Count(*) into out paramORA-22905 将 Count(*) 设置为 out 参数
【发布时间】:2014-08-23 10:57:09
【问题描述】:

我创建了一个示例 oracle 函数来返回表中的记录数。在这里

create or replace FUNCTION TEST_COUNT
RETURN NUMBER AS recCount NUMBER;
BEGIN
  SELECT COUNT(*) INTO recCount  FROM **tableName**;
  return recCount;
END TEST_COUNT;

它的编译成功,但是当我在 Oracle SQL-Developr 中使用命令

调用此函数时
SELECT * FROM TABLE (TEST_COUNT());

它给我带来了以下错误。

ORA-22905: cannot access rows from a non-nested table item
22905. 00000 -  "cannot access rows from a non-nested table item"
*Cause:    attempt to access rows of an item whose type is not known at
           parse time or that is not of a nested table type
*Action:   use CAST to cast the item to a nested table type
Error at Line: 1 Column: 22

我已关注Oracle error ORA-22905: cannot access rows from a non-nested table item,但无法找到解决方案。请建议我该怎么做?

【问题讨论】:

  • 你确定它来自那个代码吗?看起来不错,除非 **tableName** 很奇怪。同一个脚本中还有什么,因为那不是 19 行长?根本没有创建函数;或者它是用编译错误创建的;或者它已成功创建并且调用它时出现错误?如果是你打电话的时候,你是怎么做到的?
  • @AlexPoole,该函数是正确的并且没有给出任何编译错误。将 tableName 替换为数据库中表的名称。
  • 那么你什么时候收到错误 - 你怎么称呼它?脚本的第 19 行是什么?

标签: oracle stored-procedures oracle-sqldeveloper


【解决方案1】:

好吧,你只是说错了。当函数返回一个集合(例如来自create type x as table of number)时使用TABLE() table collection expression,您希望将其视为一个表,以便您可以加入它,这里不是这种情况;你返回一个简单的NUMBER

那就这样吧:

SELECT TEST_COUNT FROM DUAL;

【讨论】:

    猜你喜欢
    • 2012-11-13
    • 2019-06-08
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2013-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多