-
Notifications
You must be signed in to change notification settings - Fork 0
/
digit.sql
50 lines (44 loc) · 1.12 KB
/
digit.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
DROP FUNCTION if exists `digits`;
DELIMITER $$
CREATE FUNCTION `digits`( str longtext ) RETURNS char(32) CHARSET utf8
BEGIN
DECLARE i, len SMALLINT DEFAULT 1;
DECLARE ret CHAR(32) DEFAULT '';
DECLARE c CHAR(1);
DECLARE pos SMALLINT;
DECLARE after_p CHAR(20);
IF str IS NULL
THEN
RETURN "0.0";
END IF;
SET len = CHAR_LENGTH( str );
l:REPEAT
BEGIN
SET c = MID( str, i, 1 );
IF c BETWEEN '0' AND '9' THEN
SET ret=CONCAT(ret,c);
ELSEIF c = '.' OR c = ',' THEN
IF c = '.' THEN
SET pos=INSTR(str, '.' );
SET after_p=MID(str,pos,pos+2);
SET ret=CONCAT(FindNumericValue(ret),'.',FindNumericValue(after_p));
LEAVE l;
ELSEIF c = ',' THEN
SET pos=INSTR(str, ',');
SET after_p=MID(str,pos,pos+2);
SET ret=CONCAT(FindNumericValue(ret),'.',FindNumericValue(after_p));
LEAVE l;
END IF;
END IF;
SET i = i + 1;
END;
UNTIL i > len END REPEAT;
IF ret=''
THEN
RETURN "0.0";
END IF;
RETURN ret;
END$$
DELIMITER ;
drop procedure if exists migrationIsante;
DELIMITER $$