I'm writing a query in DB2 and I'm having a little trouble. I have a field that is actually STRING value, but all the values in the data are actually numbers. This is because these are later converted to INT in java and used in another query. I need to modify my query to actually NOT include strings that contain A through Z (so the string the query returns can be converted to an int). What would be the correct AND clause to do this? This needs to be added to a my query and not stored procedure
Asked
Active
Viewed 276 times
0
-
how is it related to mysql? – Blip Oct 20 '16 at 16:06
-
1Possible duplicate of [DB2- How to check if varchar field value has integers](http://stackoverflow.com/questions/10489703/db2-how-to-check-if-varchar-field-value-has-integers) – Arnaud Oct 20 '16 at 16:08
-
sorry accidentally tagged it – CoderRightInTheProgram Oct 20 '16 at 16:08
-
Which DB2 version/platform? – mustaccio Oct 20 '16 at 17:34
2 Answers
0
if your numbers into your zone can contain symbole numeric "," then try this
select * from yourtable
where translate(yourzone, ' ', '0123456789,')=''
else try this
select * from yourtable
where translate(yourzone, ' ', '0123456789')=''

Esperento57
- 16,521
- 3
- 39
- 45
0
if you version of db2 can use regexp_like you can do it:
With "." as decimal symbol
select * from yourtable
where REGEXP_LIKE(trim(yourzone) , '^\d+(\.\d*)?$')
With "," as decimal symbol
select * from yourtable
where REGEXP_LIKE(trim(yourzone) , '^\d+(\,\d*)?$')
Without decimal symbol ( integer only)
select * from yourtable
where REGEXP_LIKE(trim(yourzone) , '^\d+$')

Esperento57
- 16,521
- 3
- 39
- 45