oracle中查询以%结尾的数据,然后将%替换掉,有谁知道怎么写吗?

2025-02-27 09:09:03
推荐回答(3个)
回答1:

如果是40%要替换成40;还有如:40 %要替换成40,如果查询出数据为小数的记录,并替换成原来的数乘以100:
SELECT premium_alloc,
case when to_number(replace(replace(premium_alloc,' ',''),'%',''))>0
then to_number(replace(replace(premium_alloc,' ',''),'%',''))
else to_number(premium_alloc)*100 end as premium_alloc from ssa_ul_market_value
我这里没有ORACLE,用mysql的语句改的,你先试试查出来的是否正确?

替换的话就写成这样:
update ssa_ul_market_value aa ,(SELECT id,
case when to_number(replace(replace(premium_alloc,' ',''),'%',''))>0
then to_number(replace(replace(premium_alloc,' ',''),'%',''))
else to_number(premium_alloc)*100 end as premium_alloc from ssa_ul_market_value) bb set aa.premium_alloc=bb.premium_alloc
where aa.id=bb.id;//假设有ID这个关键字

回答2:

select premium_alloc from dw_ssa.ssa_ul_market_value where issuer_id = 'issuer_id%'
只需要在字段的后面加个%就行了啊

回答3:

转义符 \% ==>% select * from XXX where name like '%\%' escape '\';
'%\%' escape '\'; 这个哦 这个尾巴不要丢了