Firebird SQL – Verify if a string contains digit (number char)
From version 2.5 Firebird introduces the “SIMILAR TO” predicate which allows you to apply a subset of regular expressions in an SQL condition.
The documentation of the “SIMILAR TO” predicate is available at https://firebirdsql.org/refdocs/langrefupd25-similar-to.html
If we wanted to check if there are numbers (DIGIT) inside a string, i.e. characters from ‘0’ to ‘9’ we could simply write:
1 2 |
SELECT 'PRESENTI' AS RISULTATO FROM RDB$DATABASE WHERE 'AG8G9SG' SIMILAR TO '%[[:DIGIT:]]{1}%' |
in this case the expression
‘AG8G9SG’ SIMILAR TO ‘% [[: DIGIT:]] {1}%’ -> True
‘Giorgio’ SIMILAR TO ‘% [[: DIGIT:]] {1}%’ -> False
I hope it was useful …