Oracle ERROR: ORA-00900: invalid SQL statement

荒凉一梦 提交于 2019-12-11 12:16:21

问题


I am trying to create the following datatype with 2 functions:

-- Employee

CREATE OR REPLACE TYPE EmployeeType AS OBJECT (
    EmployeeNumber NUMBER,
    EmployeeName VARCHAR2(150),
    EmployeeAddress VARCHAR2(255),
    MAP MEMBER FUNCTION getEmployeeNumber RETURN NUMBER,
    MEMBER FUNCTION CalculateSalary RETURN FLOAT(2)
)
NOT FINAL;
CREATE OR REPLACE TYPE BODY EmployeeType AS

    MAP MEMBER FUNCTION getEmployeeNumber RETURN NUMBER IS
    BEGIN
        RETURN EmployeeNumber;
    END;
     -- function that can be overriden by subtypes, make abstract
    MEMBER FUNCTION CalculateSalary RETURN FLOAT(2) IS
    BEGIN
         -- function returns empty, has to be overwritten by fulltimeemployee
        RETURN 0.00;
    END;
END; 

However I keep getting an error stating

ERROR: ORA-00900: invalid SQL statement

Error Code: 900

Query = END

I am using RazorSQL to execute my queries, I cant seem to get the line number causing this error but through trial and error I have found it to be one of the function descriptions in my TYPE BODY definition.

I have tried adding / after the last END; but it does not help solve the issue.


回答1:


Replace FLOAT(2) with just FLOAT:

CREATE OR REPLACE TYPE EmployeeType AS OBJECT (
    EmployeeNumber NUMBER,
    EmployeeName VARCHAR2(150),
    EmployeeAddress VARCHAR2(255),
    MAP MEMBER FUNCTION getEmployeeNumber RETURN NUMBER,
    MEMBER FUNCTION CalculateSalary RETURN FLOAT
)
NOT FINAL;
/
CREATE OR REPLACE TYPE BODY EmployeeType AS

    MAP MEMBER FUNCTION getEmployeeNumber RETURN NUMBER IS
    BEGIN
        RETURN EmployeeNumber;
    END;
     -- function that can be overriden by subtypes, make abstract
    MEMBER FUNCTION CalculateSalary RETURN FLOAT IS
    BEGIN
         -- function returns empty, has to be overwritten by fulltimeemployee
        RETURN 0.00;
    END;
END; 
/

The documentation for CREATE TYPE doesn't mention this, but you can find the explanation in the topic related to CREATE FUNCTION : http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/create_function.htm RETURN datatype

RETURN datatype
For datatype, specify the data type of the return value of the function. The return value can have any data type supported by PL/SQL.
......
......
The data type cannot specify a length, precision, or scale. The database derives the length, precision, or scale of the return value from the environment from which the function is called.



来源:https://stackoverflow.com/questions/35946606/oracle-error-ora-00900-invalid-sql-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!