Verifying that the database column value contains only numbers in the select

1

I need to find out if the value of a given column of the database contains only numbers in the select itself, because if it is numeric, I need to display the value of another column.

I use an ORACLE database.

Can anyone help me with this problem?

    
asked by anonymous 30.03.2017 / 19:55

1 answer

0

I was able to solve this by using the following:

SELECT 
LENGTH(TRIM(TRANSLATE(TABELA.MEU_CAMPO_A_TESTAR, '0123456789',' '))) TESTE
FROM DUAL;

If the test returns null, the field contains only numbers.

With this I made the following CASE to search the information of one or another column as the test.

CASE WHEN ( LENGTH(TRIM(TRANSLATE(TABELA.MEU_CAMPO_A_TESTAR, '0123456789',' '))) IS NULL ) THEN TABELA.CAMPO_CASO_NUMERICO ELSE TABELA.MEU_CAMPO_A_TESTAR END AS CAMPO_APRESENTADO

That's how I solved my problem.

I hope it helps anyone looking for a similar solution.

    
30.03.2017 / 19:55