简体   繁体   中英

How to Round Decimal Result of a Calculated Column in Oracle SQL

I have a calculated column in Oracle that returns a number that is very long because of decimals (ex: 200000.0044068030021345452041589203332645).

Is there a way to convert this to say 200000.00? I tried Round, TO_DECIMAL, CAST. But nothing seems to work.

SELECT
CASE
     WHEN TRD = 'FUT'
     THEN
         CASE
             WHEN BUY_SELL = 'BUY' 
             THEN CUR / PRC 
             ELSE -CUR / PRC
         END
     ELSE NULL
END AS UNITS
FROM LAN.Details

use round

  select round(200000.0044068030021345452041589203332645,2) from dual

so in your query

SELECT
CASE
     WHEN TRD = 'FUT'
     THEN
         CASE
             WHEN BUY_SELL = 'BUY' 
             THEN round( CUR / PRC ,2)
             ELSE round(-CUR / PRC,2)
         END
     ELSE NULL
END AS UNITS
FROM LAN.Details

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