Tuesday, September 13, 2011

In Oracle, I want to know if a string value is numeric only. How can I do this?


To test a string for numeric characters, you could use a combination of the LENGTHTRIM, AND TRANSLATE functions built into Oracle.
You can use the following command:
LENGTH(TRIM(TRANSLATE(string1, ' +-.0123456789', ' ')))
string1 is the string value that you are testing
This function will return a null value if string1 is numeric. It will return a value "greater than 0" if string1 contains any non-numeric characters.

For example,
LENGTH(TRIM(TRANSLATE('123b', ' +-.0123456789',' ')));would return 1
LENGTH(TRIM(TRANSLATE('a123b', ' +-.0123456789',' ')));would return 2
LENGTH(TRIM(TRANSLATE('1256.54', ' +-.0123456789',' ')));would return null
LENGTH(TRIM(TRANSLATE ('-56', ' +-.0123456789',' ')));

1 comment:

  1. Oracle Apps R12 and Fusion Cloud Self Paced Training Videos by Industry Experts. Please check https://www.oracleappstechnical.com

    ReplyDelete