创建 UDT 函数时出现 PLS-00539 和 PLS-00538 错误

PLS-00539 and PLS-00538 errors when creating UDT functions

我正在尝试使用 Oracle 创建类型层次结构,但在创建其函数时出现错误 PLS-00539 和 PLS-00538。

我用来创建类型的代码是:

CREATE OR REPLACE TYPE VC_MNumber AS Object (   
  idno NUMBER,
  MEMBER FUNCTION  dimension   RETURN NUMBER ,
  MEMBER FUNCTION typeName RETURN VARCHAR2) NOT INSTANTIABLE NOT FINAL;
/

DROP TYPE VC_MINTEGER;

CREATE OR REPLACE TYPE VC_MInteger UNDER VC_MNumber (   
  OVERRIDING MEMBER FUNCTION  dimension   RETURN NUMBER ,
  OVERRIDING MEMBER FUNCTION typeName RETURN VARCHAR2);
/

CREATE OR REPLACE TYPE VC_MReal UNDER VC_MNumber(   
  YDCCoeff NUMBER,
  CbDCCoeff NUMBER,
  CrDCCoeff NUMBER,
  OVERRIDING MEMBER FUNCTION  typeDimension   RETURN NUMBER, 
  OVERRIDING MEMBER FUNCTION typeName RETURN VARCHAR2) FINAL;
/

到目前为止一切正常,但是当我尝试创建函数时:

CREATE OR REPLACE TYPE BODY VC_MReal AS
  OVERRIDING MEMBER FUNCTION typeDimension RETURN NUMBER IS
    var_dimension       number :=  10;
    BEGIN
        RETURN var_dimension;
    END;
   MEMBER FUNCTION typeName RETURN VARCHAR2 IS
    var_typeName        VARCHAR2(400) :=  'VC_MREAL';
    BEGIN
        RETURN var_typeName;
    END;
END;
/

我收到错误 PLS-00539 和 PLS-00538。我不知道我做错了什么。我将不胜感激。哪里错了?

PLS-00538: subprogram or cursor 'TYPENAME' is declared in an object type specification and must be defined in the object type body PLS-00539: subprogram 'TYPENAME' is declared in an object type body and must be defined in the object type specification

您在声明时犯了一些错误,请参阅内联解释:

CREATE OR REPLACE TYPE VC_MNumber AS OBJECT
(
   idno NUMBER,
   MEMBER FUNCTION dimension
      RETURN NUMBER,
   MEMBER FUNCTION typeName
      RETURN VARCHAR2
)
   NOT INSTANTIABLE NOT FINAL;
/

--DROP TYPE VC_MINTEGER;

CREATE OR REPLACE  TYPE VC_MInteger
   UNDER VC_MNumber
   (
      OVERRIDING MEMBER FUNCTION dimension
         RETURN NUMBER,
      OVERRIDING MEMBER FUNCTION typeName
         RETURN VARCHAR2
   );
/

CREATE OR REPLACE  TYPE VC_MReal
   UNDER VC_MNumber
   (
      YDCCoeff NUMBER,
      CbDCCoeff NUMBER,
      CrDCCoeff NUMBER,
      OVERRIDING MEMBER FUNCTION Dimension --<--Overriding function should have same name
         RETURN NUMBER,
      OVERRIDING MEMBER FUNCTION typeName
         RETURN VARCHAR2
   )
    FINAL;
/

CREATE OR REPLACE TYPE BODY VC_MReal
AS
   OVERRIDING MEMBER FUNCTION Dimension
      RETURN NUMBER
   IS
      var_dimension   NUMBER := 10;
   BEGIN
      RETURN var_dimension;
   END;

   OVERRIDING MEMBER FUNCTION typeName  --<-- You declared in Object type as `overriding` function and using it as `Member function` alone.
      RETURN VARCHAR2
   IS
      var_typeName   VARCHAR2 (400) := 'VC_MREAL';
   BEGIN
      RETURN var_typeName;
   END;
END;
/