oracle - Calculation in query based on the condition -


i have package in oracle contains several procedures, in 1 of procedures need calculate fee based on specific condition this:

if x_flag = 1 fee = (.5 * orders.total_count) + (.3 * orders.total_amount) else fee = (.7 * orders.total_count) + (.4 * orders.total_amount)

so, better way that?


the procedure need add calculation on :

procedure informatonrpt (  p_customerid in number,  p_orderid in number) begin      select              cusromers.costomerid,         cusromers.costomername,         cusromers.coustomerphone,         orders.price             cusromers      inner join orders             on cusromers.orderid = orders.orderid          when          p_customerid null or p_customerid = cusromers.costomerid          , p_orderid null or p_orderid = orders.orderid ;  end informatonrpt; 

customers table columns:

  • customerid
  • custumername
  • customerphone
  • ordedid

order table columns:

  • orderid
  • price
  • total_amount
  • total_count

note that: fee column doesn't exist in data base, have calculate in query

again im not sure because didnt provide enought information, need use case expresion

select c.costomerid,        c.costomername,        c.coustomerphone,        o.price,        case x_flag            when 1 (.5 * o.total_count) + (.3 * o.total_amount)            else 7 * o.total_count) + (.4 * o.total_amount)        end fee cusromers c join orders o   on c.orderid = o.orderid      

oracle case documentation


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -