本文介绍了Oracle PLSQL函数调用进入第二个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I call the return value of the first function into the second function? Here is the first function to count the number of visits a customer makes to my shop:

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;

IF
CALCULATE():= 3 - 这是我如何尝试, work--
THEN
DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost * 0.1);

IF CALCULATE() :=3 --this is how I tried and it hasnt work-- THEN DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost*0.1);

ELSIF
CALCULATE:= 6
THEN
DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost * 0.2);

ELSIF CALCULATE := 6 THEN DISCOUNTED_BILL := v_treat_cost-(v_treat_cost*0.2);

ELSIF
CALCULATE:= 9
THEN
DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost * 0.3);
ELSE
RAISE NO_DISCOUNT;

ELSIF CALCULATE := 9 THEN DISCOUNTED_BILL := v_treat_cost-(v_treat_cost*0.3); ELSE RAISE NO_DISCOUNT;

 END IF;
 END;
 /


推荐答案

变量:

    some_number_result := calculate(some_input);

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

等...

这篇关于Oracle PLSQL函数调用进入第二个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:37