3
votes

I have a package (DATA_PKG) which contains functions to return a row of data when given a primary key value. I have found a situation where one of the DATA_PKG functions fails when called by a procedure in another package (CALLER_PKG). It throws up the following error:

ora -00932: inconsistent datatypes: expected - got -

When I compile CALLER with the exact same function in the package body it works. Here is my code:

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;

When caller.calling_proc is executed this code fails with ora -00932 in the way described above.

The following code works:

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;

Can anyone tell me why this works with, what I consider to be, a trivial change to the code? The error suggests that the datatypes are inconsistent but I haven't changed any in my 'solution'.

Has this happened to anyone before? Also can anyone explain what the dashes in the error message represent? I would expect to see a datatype named here.

1
expected - got - did you remove the actual types with -?codingbiz
I have reproduced the error message literally.derek_user
I'm afraid I can't reproduce this, on 11g XE 11.2.0.2.0. Your first block of code completes successfully. Would it be possible to add your table definitions on the off-chance it's related to the types of column in your table? Also, is it possible to show the full stack trace of the error? As for the meaning of the dashes, see this question.Luke Woodward
I am guessing the /*do something with the returned record*/ in the calling_proc does datatype incompatible operations that causes the error. Otherwise I don't see any issues and I implemented the above packages and they all work well.AnBisw
Are both packages owned by the same schema? Is the table in question owned by the same schema as the packages? Is the user executing the packages the one who owns them?APC

1 Answers

0
votes

Instead of this

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

Try this (may work, though both of them are literally same)

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