I have some data I need to process, but there is no guarantee it will be valid for integer and double types (e.g. sometimes there will be alpha characters in an integer column). So in the schema I will treat these as varchar. What I want to do is use SQL functions to convert it to the right type if its valid. The problem is, I don't see the right functions for what I want. I would like something like IF(ISDIGIT(field),CINT(field),NULL)) but ISDIGIT only tests the leftmost character.. I want all the characters tested.
Thanks,
Mark
|
|
Now you can use IF(ISDIGITS(field),CINT(field),NULL)) . ISDIGITS, not ISDIGIT:) Please download the latest package.
|
Thanks for implementing this.. I think its a very useful feature for dealing with dirty input data -- which is what you find when dealing with text files.
What I forgot to mention before, is that sometimes I may be dealing with floating point data as well. So I think what I also need would be the following in terms of a regex: [-+]?[0-9]+(\.[0-9]+)?
maybe call it isNumber? I hope I am not asking for too much. Thanks for your support.
Regards,
Mark
|
GetNumber(str[, defaultValue]): return a number value(int, long, double) according to str. If failed to parse, return defaultValue(null is omitted value).
GetInt(str[, defaultValue]): return an int value according to str. If failed to parse, return defaultValue(null is omitted value).
GetLong(str[, defaultValue]): return a long value according to str. If failed to parse, return defaultValue(null is omitted value).
GetDouble(str[, defaultValue]): return a double value according to str. If failed to parse, return defaultValue(null is omitted value).
GetNumber is a special function, which allows defaultValue to use non-number value. For instance,
select getNumber(field,field),...
Object value=resultSet.getObject(1);
if(value instance Number){//Parsed number, Integer, Double, or Double
}else{
value=restultSet.getString(1);//Now you can see the invalid data format.
}
Please download the latest package.
|
Thank you. I will test it.
I just want to say that this feature (GetNumber,etc) is still very helpful eventhough you have implemented: http://www.hxtt.com/support_view_issue.jsp?id=1159435932
The reason is that some users may want complete control of dealing with dirty data and do some custom workaround vs. having the driver return a null.
Thanks,
Mark
|