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

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

May 10, 2018 pm 02:19 PM
character string

--如何将一个字符串中的所有非数字(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

 

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the method of converting int type to string in PHP Detailed explanation of the method of converting int type to string in PHP Mar 26, 2024 am 11:45 AM

Detailed explanation of the method of converting int type to string in PHP

How to determine whether a Golang string ends with a specified character How to determine whether a Golang string ends with a specified character Mar 12, 2024 pm 04:48 PM

How to determine whether a Golang string ends with a specified character

How to check if a string starts with a specific character in Golang? How to check if a string starts with a specific character in Golang? Mar 12, 2024 pm 09:42 PM

How to check if a string starts with a specific character in Golang?

How to repeat a string in python_python repeating string tutorial How to repeat a string in python_python repeating string tutorial Apr 02, 2024 pm 03:58 PM

How to repeat a string in python_python repeating string tutorial

How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP Mar 04, 2024 am 09:36 AM

How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP

PHP string manipulation: a practical way to effectively remove spaces PHP string manipulation: a practical way to effectively remove spaces Mar 24, 2024 am 11:45 AM

PHP string manipulation: a practical way to effectively remove spaces

PHP String Matching Tips: Avoid Ambiguous Included Expressions PHP String Matching Tips: Avoid Ambiguous Included Expressions Feb 29, 2024 am 08:06 AM

PHP String Matching Tips: Avoid Ambiguous Included Expressions

PHP techniques for deleting the last two characters of a string PHP techniques for deleting the last two characters of a string Mar 23, 2024 pm 12:18 PM

PHP techniques for deleting the last two characters of a string

See all articles