Home > Database > Mysql Tutorial > 如何将一个字符串中的所有非数字(0-9及小数点)字符全部除去_MySQL

如何将一个字符串中的所有非数字(0-9及小数点)字符全部除去_MySQL

ringa_lee
Release: 2018-05-10 14:19:37
Original
3815 people have browsed it

--如何将一个字符串中的所有非数字(0-9及小数点)字符全部除去
create function clear_num (@s nvarchar(100))--创建自定义函数
returns nvarchar(100)
as
begin
 while PATINDEX('%[^0-9.]%',@s)>=1
   set @s=replace(@s,substring(@s,PATINDEX('%[^0-9.]%',@s),1),'')--使用replace(替换非数字字符为空字符串)、substring(确定被替换的字符)和patindex(确定非数字字符串的位置)三个函数
 return(@s)
end
--使用
select dbo.clear_num('12qw34.as56zx')
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template