ORA-22905将Count(*)设置为out param

时间:2014-07-02 15:09:03

标签: oracle stored-procedures oracle-sqldeveloper

我已经创建了一个示例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但无法达成解决方案。请建议我该怎么做?

1 个答案:

答案 0 :(得分:2)

嗯,你只是说错了。当函数返回要作为表格处理的集合(例如,来自create type x as table of number)时,将使用TABLE() table collection expression,以便您可以加入它,这不是这里的情况;您正在返回一个简单的NUMBER

所以就这样做:

SELECT TEST_COUNT FROM DUAL;