-1

我在 oracle sql plus 中创建一个函数,它以 empno 作为参数并返回它的薪水。但它没有被创建,我哪里出错了?

这是我的功能:

CREATE FUNCTION GETEMPSALARY (EMPNUMBER IN INTEGER) RETURN INTEGER
IS
EMPSALARY INTEGER;
BEGIN
SELECT SAL INTO EMPSALARY FROM EMP WHERE EMP.EMPNO = EMPNUMBER;
RETURN EMPSALARY;
END GETEMPSALARY;

这是错误:

Error at line 1: 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


1. CREATE FUNCTION GETNAMES1 (EMPID IN INTEGER) RETURN VARCHAR(20)
2. IS
3. EMPNAME VARCHAR(50);
4

1 回答 1

1

你最后错过了 / 。

CREATE FUNCTION GETEMPSALARY (EMPNUMBER IN INTEGER) RETURN INTEGER
IS
DECLARE
EMPSALARY INTEGER;
BEGIN
SELECT SAL INTO EMPSALARY FROM EMP WHERE EMP.EMPNO = EMPNUMBER;
RETURN EMPSALARY;
END GETEMPSALARY;
/

编辑:由于您的新错误是完全不同的功能!

CREATE FUNCTION GETNAMES1 (EMPID IN INTEGER) RETURN VARCHAR(20)

你不应该指定回报的精度,所以把

 RETURN VARCHAR2

也不用VARCHAR,只用VARCHAR2

和 for 语句被忽略;

SQL> CREATE FUNCTION GETEMPSALARY (EMPNUMBER IN INTEGER) RETURN INTEGER
  2  IS
  3  EMPSALARY INTEGER;
  4  BEGIN
  5  SELECT SAL INTO EMPSALARY FROM EMP WHERE EMP.EMPNO = EMPNUMBER;
  6  RETURN EMPSALARY;
  7  END GETEMPSALARY;
  8  /

Warning: Function created with compilation errors.

SQL> show errors
Errors for FUNCTION GETEMPSALARY:

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1      PL/SQL: SQL Statement ignored
5/32     PL/SQL: ORA-00942: table or view does not exist
SQL>

你看到的后续错误是什么,因为这个错误后面应该是一个真正的错误

于 2012-12-07T12:10:32.677 回答