0 Replies Latest reply: Jun 19, 2013 4:49 PM by JohnHopper RSS

    ORA-00932: inconsistent datatypes (Oracle 11.2)

    JohnHopper

      Hi all,

       

      I get the following error message when trying to create object data type instance using static Java method.

      getter method works fine. I cannot explain why the static method does not work.

      any help much appreciated. code below.

      thanks!

       

      SQL Error: ORA-00932: inconsistent datatypes: expected a return value that is an instance of a user defined Java class convertible to an Oracle type got an object that could not be converted

       

      /* java code */

      package pkg;

       

      import java.sql.*;

       

      public class Person implements SQLData {

       

          private String sql_type = "Person";

          public int width;

       

          static public Person create(){

              Person p = new Person();

              p.width = 1;

              return p;

          }

        

          public String getSQLTypeName() throws SQLException {

              return sql_type;

          }

       

          public void readSQL(SQLInput stream, String typeName) throws SQLException {

              sql_type = typeName;

              width = stream.readInt();

          }

       

          public void writeSQL(SQLOutput stream) throws SQLException {

              stream.writeInt(width);

          }

       

          public int getWidth(){

              return width;

          }

          

      }

      /* end of java code*/

       

      /* sql code */

       

      CREATE OR REPLACE

      TYPE person AS OBJECT

      EXTERNAL NAME 'pkg.Person' LANGUAGE JAVA USING SQLData(

        width number EXTERNAL NAME 'width'

        , STATIC FUNCTION CREATE_PERSON RETURN PERSON EXTERNAL NAME 'create() return pkg.Person'

        , MEMBER FUNCTION get_width return number EXTERNAL NAME 'getWidth() return java.lang.int'

      );

       

      CREATE TABLE people(

        human Person

      );

       

      INSERT INTO PEOPLE VALUES (PERSON(1) );

      SELECT P.HUMAN.GET_WIDTH() FROM PEOPLE P;

       

      INSERT INTO PEOPLE VALUES (PERSON.CREATE_PERSON() );  -- fails with ORA-00932

       

      /* end sql code */