You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle中替换价格逗号为句号后前导0丢失的修复求助

解决Oracle生成XLS时价格前导0丢失的问题

针对你遇到的价格值(如0,1)替换后变成.1的问题,可通过以下两种方案解决:

方案一:若函数返回数值类型(推荐)

如果PKPRIXVENTE.GET_PRIX_VENTE返回的是数值而非字符串,直接用to_char指定格式化规则,强制保留整数部分的前导0:

select 
'"'||arccode||'"'  "ean_code",
'"'||artcexr||'"'  as "product_id",
'"'||to_char(artdcre,'yyyy-mm-dd')||'"'  as "created_at",
'"'||null||'"'  "brand",
'"'||null||'"'  "description",
'"'||to_char(PKPRIXVENTE.GET_PRIX_VENTE(arvcinv,207,1,sysdate), 'FM9999999990.99')||'"'  as "price",
from  artrac
  • 格式说明:FM用于去除数值前后的多余空格;0表示该位置必须显示数字(确保整数部分为0时不会被省略);9表示可选数字(无值时不显示);.99保留两位小数(可根据需求调整位数)。

方案二:若函数返回带逗号的字符串

如果函数返回的是类似,1的字符串(缺失前导0),通过正则表达式或条件判断补全前导0:

正则表达式方式

select 
'"'||arccode||'"'  "ean_code",
'"'||artcexr||'"'  as "product_id",
'"'||to_char(artdcre,'yyyy-mm-dd')||'"'  as "created_at",
'"'||null||'"'  "brand",
'"'||null||'"'  "description",
'"'||regexp_replace(replace(PKPRIXVENTE.GET_PRIX_VENTE(arvcinv,207,1,sysdate), ',', '.'), '^\.', '0.')||'"'  as "price",
from  artrac

条件判断方式

select 
'"'||arccode||'"'  "ean_code",
'"'||artcexr||'"'  as "product_id",
'"'||to_char(artdcre,'yyyy-mm-dd')||'"'  as "created_at",
'"'||null||'"'  "brand",
'"'||null||'"'  "description",
'"'||case 
         when replace(PKPRIXVENTE.GET_PRIX_VENTE(arvcinv,207,1,sysdate), ',', '.') like '.%' 
         then '0' || replace(PKPRIXVENTE.GET_PRIX_VENTE(arvcinv,207,1,sysdate), ',', '.')
         else replace(PKPRIXVENTE.GET_PRIX_VENTE(arvcinv,207,1,sysdate), ',', '.')
       end||'"'  as "price",
from  artrac

内容的提问来源于stack exchange,提问作者nullonprog

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 11:25:28