Oracle PLSQL函数调用第二个函数

时间:2012-11-25 11:26:10

标签: database oracle plsql

如何将第一个函数的返回值调用到第二个函数中?这是第一个计算客户对我店的访问次数的函数:

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;
 /

1 个答案:

答案 0 :(得分:1)

将函数调用分配给变量:

    some_number_result := calculate(some_input);

    if some_number_result = 1 then 
       -- do stuff
    end if;

等...