Hi Experts,
The requirement is to write a procedure to accept two variables one is v_input_number and the other is v_input_cid.
If I pass positive number for a particular cid the number should sum with negative value.
If I pass negative number for a particular cid the number should sum with positive value
The data in the table as below.
cid val1 val2
A -5 10
B 15 -7
C -8 4
D -20 30
I have tried the below logic and stuck up. It's not completed.
CREATE OR REPLACE PROCEDURE p1 (v_input_number NUMBER,v_input_cid NUMBER)
IS
v_result NUMBER;
BEGIN
SELECT CASE WHEN v_input_number<0 THEN v_input_number
WHEN v_input_number>=0 THEN v_input_number
END as result INTO v_result
FROM test_table WHERE cid=v_input_cid;
DBMS_OUTPUT.PUT_LINE(v_result);
END;
Expected Result :
I/P v_input_number=-2 v_input_cid=A calculation -2+10 O/P 8
calculation
I/P v_input_number=5 v_input_cid=B calculation 5-7 O/p -2
calculation
I/P v_input_number=10 v_input_cid=3 calculation 10-8 O/P 2
Please help me with the logic.
Thanks in advance.