plsql - Correct way of writing PL SQL conditions -


below condition table request.

level of     till 300$       301-500$      501-3400$ credit card  usage in 3 month  0%            0%               0%             0% 1-30%         30%              0%             0% 31-50%        50%              0%             0% 51-60%        50%              15%            0% 61-70%        100%             15%            0% 70%~          100%             30%            30% 

my task retrieve information mentioned above in 1 table using pl sql. have table request consists of 3 columns client_id, level_3m , credit_limit output(for example) should using above information:

level_3m     credit_limit($)      new_limit(%)  0                50                 0 45               400                0 45               250                50 65               350                15 80               1500               30 

what have done far? here own script:

declare     v_level        varchar2(100);     v_credit_limit varchar2(100);     v_id           varchar2(100);     new_limit      varchar2(100); begin     select level_3m,            credit_limit       v_level, v_credit_limit       request      v_id = a.client_id;      --this "till 300$" condition     if v_level = 0        , v_credit_limit =< 300       new_limit := 0;     elsif v_level >= 1           , v_level <= 30           , v_credit_limit =< 300       new_limit := 30;     elsif v_level >= 31           , v_level <= 50           , v_credit_limit =< 300       new_limit := 50;     elsif v_level >= 51           , v_level <= 60           , v_credit_limit =< 300       new_limit := 50;     elsif v_level >= 61           , v_level <= 70           , v_credit_limit =< 300       new_limit := 100;     elsif v_level >= 70           , v_credit_limit =< 300       new_limit := 100;     end if; end;  /   --the other conditions written same manner above one. 

i new pl/sql please tell condition right? or there more simple way write conditions?

you're doing if statements right.

another option using case. it's same looks little neater, if you're writing out many elsif clauses.

    case       when v_level=0  , v_credit_limit=<300 new_limit:=0       when v_level>=1 , v_level <=30 , v_credit_limit =<300 new_limit:=30       when v_level>=31 , v_level<=50 , v_credit_limit=<300 new_limit:=50       when v_level>=51 , v_level<=60 , v_credit_limit=<300 new_limit:=50       when v_level>=61 , v_level<=70 , v_credit_limit=<300 new_limit:=100       when v_level>=70 , v_credit_limit=<300 new_limit:=100     end case 

it doesn't matter whether use if or case in opinion.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -