Oracle PLSQL 函数调用到第二个函数
Posted
技术标签:
【中文标题】Oracle PLSQL 函数调用到第二个函数【英文标题】:Oracle PLSQL function call into a second function 【发布时间】:2012-11-25 11:26:10 【问题描述】:如何将第一个函数的返回值调用到第二个函数中?这是第一个计算客户访问我的商店次数的函数:
CREATE OR REPLACE FUNCTION CALCULATE ( NUM CUSTOMER.CUST_VISIT%TYPE)
RETURN NUMBER
IS
V_CUST_VISIT NUMBER(3);
V_COUNT INTEGER;
BEGIN
SELECT CUST_VISIT
INTO V_CUST_VISIT
FROM CUSTOMER, BOOKING
WHERE CUSTOMER.CUST_ID = BOOKING.CUST_ID;
SELECT MAX(COUNT(*))
INTO v_count
FROM BOOKING
GROUP BY CUST_ID
HAVING count(*)>=0;
CASE v_count
WHEN 3 THEN v_cust_visit:= v_count;
DBMS_OUTPUT.PUT_LINE('10% DISCOUNT DUE');
WHEN 6 THEN v_cust_visit:= v_count;
DBMS_OUTPUT.PUT_LINE('20% DISCOUNT DUE');
WHEN 9 THEN v_cust_visit:= v_count;
DBMS_OUTPUT.PUT_LINE('30% DISCOUNT DUE');
ELSE v_cust_visit:= v_count;
DBMS_OUTPUT.PUT_LINE('OOPS NO DISCOUNT DUE YET! AFTER THREE BOOKINGS');
END CASE;
END;
/
Where in the second function:
CREATE OR REPLACE FUNCTION CALC_BILL
(BILL_NUM TREATMENT.TREAT_COST%TYPE)
RETURN NUMBER
IS
CUST_ID VARCHAR2(4);
TREAT_COST NUMBER(10,2);
v_TREAT_cost TREATMENT.TREAT_COST%TYPE;
DISCOUNTED_BILL NUMBER(10,2);
NO_DISCOUNT EXCEPTION;
BEGIN
SELECT TREAT_COST
INTO v_treat_cost
FROM CUSTOMER C, TREATMENT T, TREAT_SESSION TS
WHERE C.CUST_ID = TS.CUST_ID
AND T.TREAT_ID = TS.TREAT_ID;
如果 CALCULATE() :=3 --这是我尝试过的方法,但没有奏效-- 然后 DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost*0.1);
ELSIF 计算:= 6 然后 DISCOUNTED_BILL := v_treat_cost-(v_treat_cost*0.2);
ELSIF 计算 := 9 然后 DISCOUNTED_BILL := v_treat_cost-(v_treat_cost*0.3); 别的 提高 NO_DISCOUNT;
END IF;
END;
/
【问题讨论】:
你不应该在CALCULATE
中使用CALL_BILL
吗?
【参考方案1】:
将函数调用分配给一个变量:
some_number_result := calculate(some_input);
if some_number_result = 1 then
-- do stuff
end if;
等等……
【讨论】:
感谢 Greg,这就是我现在所做的,它看起来不错 v_CUST_VISIT := CALCULATE(DISCOUNTED_BILL); IF v_CUST_VISIT = 3 THEN DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost*0.1);结束 IF;以上是关于Oracle PLSQL 函数调用到第二个函数的主要内容,如果未能解决你的问题,请参考以下文章