I have to write an sql command that will return null if a string is not an integer, return the string contents if it is an integer. This sql command will be embedded in an application and cannot reference a custom function.
The following sql works correctly if the INPUT_STRING is only one digit
select DECODE( TRANSLATE('[%INPUT_STRING%]','0123456789',' '), NULL, '[%INPUT_STRING%]',' ') from dual
For example, the following will return '3' when user enters '3'
select DECODE( TRANSLATE('3','0123456789',' '), NULL, '3',' ') from dual
But if user enters '31', it will fail.
Can you provide an SQL that will return the contents of INPUT_STRING when it contains only the digits 0123456789.
A second best alternative would be returning Null if INPUT_STRING contains a decimal point, otherwise return contents of INPUT_STRING
select input_string from dual
where regexp_like(input_string,'
return input_string if integer or NULL if not
select regexp_substr(input_string