2 easy firebird sql functions to convert any string to real or integer.
String to real
1 2 3 4 5 6 7 8 |
CREATE OR ALTER FUNCTION string_to_float (ch varCHAR(1000)) RETURNS float AS DECLARE VARIABLE nr float; BEGIN if ((ch ='') or (ch is null)) then ch=0; nr = CAST(replace(ch,',','.') AS float); return nr; WHEN ANY DO nr = 0; END ; |
String to integer
1 2 3 4 5 6 7 8 9 10 11 12 |
CREATE OR ALTER FUNCTION string_to_integer ( ch varCHAR(1000)) RETURNS integer AS DECLARE VARIABLE nr integer; BEGIN nr = CAST(ch AS integer); return nr; WHEN ANY DO nr = 0; END ; |
Usage example
1 2 3 4 |
select string_to_integer(customers.phonenumber) from customers |