简体   繁体   中英

Round in Oracle SQL

I have below SQL that returns the result, but I want the price to rounded to 6 decimal places.

select opt.blo,
  opt.premiumcurrency,
     case
      when opt.structurename is not null then opt.basemarketprice /100
        when pct = 1 then opt.basemarketprice /100
        when pct = 2 then opt.termmarketprice / opt.notional
        when opt.notionalcurrency = opt.premiumcurrency  then opt.basemarketprice /100
        else opt.termmarketpricepercent /100
    end as round(price,6)
from interafce opt

When I add below it gives me error

ORA-00923: FROM keyword not found where

Thanks for your help.

The case needs to go into the round() . You are confusing the function with the alias:

 round(case when opt.structurename is not null then opt.basemarketprice /100
            when pct = 1 then opt.basemarketprice /100
            when pct = 2 then opt.termmarketprice / opt.notional
            when opt.notionalcurrency = opt.premiumcurrency  then opt.basemarketprice /100
            else opt.termmarketpricepercent /100
       end, 6) as roundedPrice

end as round(price,6) does'nt work. You are aliasing the column as "round(price,6)"

rather do a

select .....
....
when opt.structurename is not null then round(opt.basemarketprice /100,6)
        when pct = 1 then round(opt.basemarketprice /100,6)
        when pct = 2 then round(opt.termmarketprice / opt.notional,6)
        when opt.notionalcurrency = opt.premiumcurrency  then round(opt.basemarketprice /100,6)
        else round(opt.termmarketpricepercent /100,6)
    end as rounded_price

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM