簡體   English   中英

全面了解Oracle SQL

[英]Round in Oracle SQL

我在下面的SQL中返回結果,但是我希望價格四舍五入到小數點后6位。

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

當我在下面添加時,它給我錯誤

ORA-00923:在哪里找不到FROM關鍵字

謝謝你的幫助。

case需要進入round() 您將函數與別名混淆:

 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

結束,因為回合(價格,6)不起作用。 您將列別名為“ round(price,6)”

寧願做一個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM