方法一:
目標表contract_service_content數據實例
配置表configdb的數據實例,如果有權限訪問數據庫的 mysql.help_topic 表 則不用創建配置表 直接用mysql.help_topic表中的help_topic_id,不然就要創建一個表ID連續的配置表
select spc_id,fee,cast(group_concat(c order by pos separator '') as unsigned) as mixed1 from ( /*分割fee字符串 並將將字符的asc碼在48到57之間的提取出來(也就是數字)*/ select v.spc_id , v.fee, iter.pos,substr(v.fee,iter.pos,1) as c from contract_service_content v, ( select id pos from configdb ) iter where iter.pos <= length(v.fee) and ascii(substr(v.fee,iter.pos,1)) between 48 and 57 ) y group by spc_id,fee order by spc_id
運行結果:
此方法參考:https://www.jianshu.com/p/289953083796
方法二:
select CAST('21歲' as SIGNED); select CONVERT('021歲', SIGNED)
上面兩條sql 運行結果都是21
此方法明細參考 https://www.cnblogs.com/baby123/p/11716896.html 有詳細介紹
方法一 可以提取提取字符串中的所有數字
方法二只能提取到字符串前面的數字,有局限性