【发布时间】:2016-03-08 05:28:00
【问题描述】:
我正在尝试在“if”条件中使用“if”条件来创建函数。 我知道语法看起来有点像下面,但我无法在我的代码中做到这一点。
IF sales > (quota + 200) THEN
bonus := (sales - quota)/4;
ELSE
IF sales > quota THEN
bonus := 50;
ELSE
bonus := 0;
END IF;
END IF;
以下是我要完成的程序。请帮帮我。 它的功能是在给定的通话次数中查找电话账单金额 和计划类型
CREATE OR REPLACE FUNCTION BILL(NUM_OF_CALLS NUMBER, PLAN_TYPE NUMBER) RETURN NUMBER IS :
BILL_AMT NUMBER;
MIN_1 NUMBER :=150;
MIN_2 NUMBER :=1000;
BEGIN
IF PLAN_TYPE:=150 THEN
IF NUM_OF_CALLS<150 THEN
BILL_AMT:=MIN_1;
ELSIF NUM_OF_CALLS BETWEEN 151 AND 250 THEN
BILL_AMT:=MIN_1+(NUM_OF_CALLS-150);
ELSIF NUM_OF_CALLS BETWEEN 251 AND 400 THEN
BILL_AMT:=MIN_1+(100*1)+(NUM_OF_CALLS-250)*0.5;
ELSIF NUM_OF_CALLS>400 THEN
BILL_AMT:=MIN_1+(100*1)+(150*0.5)+(NUM_OF_CALLS-400)*0.3;
END IF;
ELSE PLAN_TYPE:=500 THEN
IF NUM_OF_CALLS<1000 THEN
BILL_AMT:=MIN_2;
ELSIF NUM_OF_CALLS BETWEEN 1001 AND 1500 THEN
BILL_AMT:=MIN_2+(NUM_OF_CALLS-1000)*0.50;
ELSIF NUM_OF_CALLS>1500 THEN
BILL_AMT:=MIN_2+(500*0.50)+(NUM_OF_CALLS-1500)*0.25;
END IF;
END IF;
RETURN BILL_AMT;
END;
以下是错误
SQL> 显示错误 FUNCTION BILL 错误:
LINE/COL ERROR
11/14 PLS-00103: Encountered the symbol "=" when expecting one of the
following:
. ( * @ % & = - + < / > at in is mod remainder not rem then
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
The symbol "* was inserted before "=" to continue.
22/22 PLS-00103: Encountered the symbol "THEN" when expecting one of
the following:
* & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
31/6 PLS-00103: Encountered the symbol "IF" when expecting one of the
following:
; <an identifier> <a double-quoted delimited-identifier>
current delete exists prior <a single-quoted SQL string>
【问题讨论】:
-
这似乎是一种 Pascal 语言,但是 := 里面如果是错误的
-
是Oracle PL SQL...
-
你遇到了什么错误?
-
Ed:发布错误
-
@ClaudioDaffra,是的,PL/SQL 至少在语法层面受到 Ada 的严重影响,Ada 借鉴了 Pascal 以及其他影响。
标签: oracle function if-statement plsql oracle11g