Extract number from string
-
Hi.. My function is to extract only number from given string. i m using mysql database and i m new to the syntax. is there anyone help me pls? thanks in advance! ===================== BEGIN DECLARE @Count INT DECLARE @IntNumbers VARCHAR(1000) SET @Count = 0 SET @IntNumbers = '' WHILE @Count <= LEN(@String) BEGIN IF SUBSTRING(@String,@Count,1) >= '0' AND SUBSTRING(@String,@Count,1) <= '9' BEGIN SET @IntNumbers = @IntNumbers + SUBSTRING(@String,@Count,1) END SET @Count = @Count + 1 END RETURN @IntNumbers ============================================= The following error Message is shown. Script line: 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@locator VARCHAR(20)) RETURNS INT AS BEGIN DECLARE @cnt INT DECLARE' at line 1
-
Hi.. My function is to extract only number from given string. i m using mysql database and i m new to the syntax. is there anyone help me pls? thanks in advance! ===================== BEGIN DECLARE @Count INT DECLARE @IntNumbers VARCHAR(1000) SET @Count = 0 SET @IntNumbers = '' WHILE @Count <= LEN(@String) BEGIN IF SUBSTRING(@String,@Count,1) >= '0' AND SUBSTRING(@String,@Count,1) <= '9' BEGIN SET @IntNumbers = @IntNumbers + SUBSTRING(@String,@Count,1) END SET @Count = @Count + 1 END RETURN @IntNumbers ============================================= The following error Message is shown. Script line: 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@locator VARCHAR(20)) RETURNS INT AS BEGIN DECLARE @cnt INT DECLARE' at line 1
Here is a sample function which is doing what you want: User Defined Function to Extract Only Numbers From String[^]
_
-
Here is a sample function which is doing what you want: User Defined Function to Extract Only Numbers From String[^]
_
-
It's working in SQL Server dude. Since you are trying to execute it on MySql, you probably have to find which line should be replaced with the proper corresponding sql syntax in MySql.
_