0

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 --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 := 9 THEN DISCOUNTED_BILL := v_treat_cost-(v_treat_cost*0.3); ELSE RAISE NO_DISCOUNT;

 END IF;
 END;
 /
1
  • 3
    Shouldn't you use CALL_BILL in your CALCULATE? Commented Nov 25, 2012 at 11:43

1 Answer 1

1

Assign the function call to a variable:

    some_number_result := calculate(some_input);

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

etc...

Sign up to request clarification or add additional context in comments.

1 Comment

thanks Greg, this is what I did for now it looks good v_CUST_VISIT := CALCULATE(DISCOUNTED_BILL); IF v_CUST_VISIT = 3 THEN DISCOUNTED_BILL:= v_treat_cost-(v_treat_cost*0.1); End IF;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.