2016-12-07 64 views
0

我試圖在Oracle Apex 5 SQL命令中創建這個函數,並導致了這個錯誤'ORA-24344:編譯錯誤成功'。你爲什麼這麼認爲?我試圖創建一個隨機生成的代碼。函數創建時編譯錯誤成功,爲什麼?

CREATE OR REPLACE FUNCTION generate_code() 
    return varchar2 
    AS 
    code varchar2; 
    BEGIN 
    code := DBMS_RANDOM.value(1,100); 
    return code; 
    END; 

回答

1

錯誤的語法,請參見下面

正確的語法是

CREATE OR REPLACE FUNCTION generate_code 

    return varchar2 
    AS 
    code varchar2(100); 
    BEGIN 
    code := DBMS_RANDOM.value(1,100); 
    return code; 
    END; 

原始語法錯誤描述:

SQL> CREATE OR REPLACE FUNCTION generate_code() 
    2 
    3  return varchar2 
    4  AS 
    5  code varchar2; 
    6  BEGIN 
    7  code := DBMS_RANDOM.value(1,100); 
    8  return code; 
    9  END; 
10 
11/

Warning: Function created with compilation errors. 

SQL> show error 
Errors for FUNCTION GENERATE_CODE: 

LINE/COL ERROR 
-------- ----------------------------------------------------------------- 
1/24  PLS-00103: Encountered the symbol ")" when expecting one of the 
     following: 
     <an identifier> <a double-quoted delimited-identifier> 
     current delete exists prior 
+0

你先生是了不起的!謝謝,我的問題解決了。 –