2017-07-14 47 views
0

如何將字符串轉換爲雙精度或小數?在Exact Online(REST API)中,我嘗試使用字符串字段中的十進制值進行計算。例如items.netprice + items.notes。字段items.notes包含十進制值。 試用castconvert結合floatdecimal字符串加倍或小數

+0

目前尚不清楚你在做什麼。你能證明你給的東西到目前爲止嗎? –

回答

1

我會用類似的解決方案:

select case 
     when regexp_replace(c, '[^0-9.]', '', 1, 0, 'g') = c 
     then to_number(c) 
     else null 
     end  
from (select '123.45' c 
     from [email protected] 
     union all 
     select '123invalid.45' c 
     from [email protected] 
     ) 

caseregexp_replace確保非數量爲空返回。如果認爲有必要,您可能需要將其更改爲錯誤。