Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Based on input sum positive or negative value

Ram_AApr 23 2019 — edited Apr 25 2019

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.

This post has been answered by Ram_A on Apr 24 2019
Jump to Answer
Comments
Post Details
Added on Apr 23 2019
8 comments
942 views