2014-10-05 118 views
-2

为什么我在这里收到编译错误?表中所有属性的名称都是正确的。此外,该表存在。“编译错误”与功能

SQL> create or replace function user_annual_comp(f_eno emp1.empno%type) return number 
    2 is 
    3 f_sal emp1.salary%type; 
    4 f_comm emp1.comm%type; 
    5 annual_comm number; 
    6 begin 
    7 select salary into f_sal from emp1 where empno = f_eno; 
    8 select comm into f_comm from emp1 where empno = f_eno; 
    9 if f_sal is null then 
10  f_sal := 0; 
11 end if; 
12 if f_comm is null then 
13  f_comm := 0; 
14 end if; 
15 annual_comm = (f_sal + f_comm) * 12; 
16 return annual_comm; 
17 end; 
18/

结果:

Warning: Function created with compilation errors. 

我该如何解决这个问题?

+0

没有关于错误信息的更多具体信息?哪条线? – Juru 2014-10-05 07:48:02

+0

什么'show error'给你? – 2014-10-05 15:31:19

+0

希望OP在'SQL * Plus'中编译函数:-) – 2014-10-05 16:06:02

回答

1

PL/SQL中的赋值运算符为:=,而=为相等比较运算符。换行15到

annual_comm := (f_sal + f_comm) * 12; 

分享和享受。

0

您可以编写一个全功能的简单的SQL:

Select (nvl(sal,0) + nvl(comm,0))*12 as "annual_comm" 
    From emp 
    Where empno = input_emp_no; 

切勿使用PL/SQL时,情况也可能在普通的SQL来完成。

不过,如果你还是坚持写一个函数,然后在体内的逻辑可以被改写为:

annual_comm := (nvl(sal,0) + nvl(comm,0))*12

,摆脱了IF-END IF块。