plsql ora -00932:不一致的数据类型:expected - got -

时间:2012-08-18 09:17:37

标签: oracle plsql oracle11g

我有一个包(DATA_PKG),它包含在给定主键值时返回一行数据的函数。我发现一种情况,其中一个DATA_PKG函数在被另一个包(CALLER_PKG)中的过程调用时失败。它引发了以下错误:

ora -00932: inconsistent datatypes: expected - got -

当我在包体中使用完全相同的函数编译CALLER时,它可以工作。这是我的代码:

CREATE OR REPLACE PACKAGE "DATA_PKG" AS

  FUNCTION data_function
   (primary_i IN table_name.id%type)
   RETURN table_name%ROWTYPE;

END DATA_PKG;

/

CREATE OR REPLACE PACKAGE BODY "DATA_PKG" AS

  FUNCTION data_function
   (primary_i IN table_name.id%type)
   RETURN table_name%ROWTYPE AS
   retval table_name%ROWTYPE;
  BEGIN
    SELECT * INTO retval FROM table_name WHERE id = primary_i;

    RETURN retval;
  END data_function;

END DATA_PKG;

/

CREATE OR REPLACE PACKAGE "CALLER" AS

  PROCEDURE calling_proc
   (key_i IN table_name.id%TYPE);

END CALLER;

/

CREATE OR REPLACE PACKAGE BODY "CALLER" AS

  PROCEDURE calling_proc
   (key_i IN table_name.id%TYPE) AS
   table_rec table_name%rowtype;
  BEGIN
   table_rec := data_pkg.data_function(primary_i=>key_i);
   /*
     do something with the returned record
   */
  END calling_proc;

END CALLER;

当执行caller.calling_proc时,此代码以上述方式使用ora -00932失败。

以下代码有效:

CREATE OR REPLACE PACKAGE BODY "CALLER" AS

  FUNCTION data_function
   (primary_i IN table_name.id%type)
   RETURN table_name%ROWTYPE AS
   retval table_name%ROWTYPE;
  BEGIN
    SELECT * INTO retval FROM table_name WHERE id = primary_i;

    RETURN retval;
  END data_function;

  PROCEDURE calling_proc
   (key_i IN table_name.id%TYPE) AS
   table_rec table_name%rowtype;
  BEGIN
   table_rec := data_function(primary_i=>key_i);
   /*
     do something with the returned record
   */
  END calling_proc;

END CALLER;

任何人都可以告诉我为什么这样做,我认为是什么,对代码的微不足道的改变?该错误表明数据类型不一致,但我在“解决方案”中没有更改任何内容。

之前有人发生过这种情况吗?任何人都可以解释错误消息中的破折号代表什么?我希望看到一个名为here的数据类型。

1 个答案:

答案 0 :(得分:0)

而不是这个

table_rec := data_pkg.data_function(primary_i=>key_i);

尝试这个(可能有效,但两者都完全相同)

SELECT data_pkg.data_function(primary_i=>key_i)
  INTO table_rec
  FROM dual;