2016-11-24 90 views
0

我想提出一個自定義函數返回一個排的最大的一個表:的Oracle SQL自定義功能錯誤

CREATE OR REPLACE FUNCTION getMax 
    RETURN DECIMAL(3,2) 
    IS l_getMax DECIMAL(3,2); 
     BEGIN 
      SELECT MAX(PRICE) 
      INTO l_getMax 
      FROM TABLE; 
     RETURN l_getMax; 
    END getMax; 

它編譯就好了,當我做了數據類型的整數,但後來我意識到它應該是小數,當我改變了,我得到了以下錯誤:

Error(2,18): PLS-00103: Encountered the symbol "(" when expecting one of the following:  . @ % ; is authid as cluster order using external character deterministic parallel_enable pipelined aggregate result_cache 

Error(3,4): PLS-00103: Encountered the symbol "IS" when expecting one of the following:  , * & - +/at mod remainder rem <an identifier> <a double-quoted delimited-identifier> <an exponent (**)> as from into || multiset bulk year day 

Error(9,16): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:  end not pragma final instantiable order overriding static member constructor map 
+3

只是使它成爲一個'number'。 Oracle對數字非常靈活。 –

+3

'RETURN DECIMAL(3,2)'應該是'RETURN DECIMAL' –

+0

@a_horse_with_no_name,你可以把它作爲答案嗎? –

回答

0

試試這個:

create table t(
col DECIMAL(3,2) 
); 

insert into t values (3.2); 
insert into t values (2.1); 
insert into t values (1.99); 


    CREATE OR REPLACE FUNCTION getMax 
    RETURN NUMBER 
    AS 
     l_getMax DECIMAL(3,2); 
    BEGIN 
      SELECT MAX(col) INTO l_getMax FROM t; 
     RETURN l_getMax; 
    END getMax; 
    /

    select getMax from dual;