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?
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?
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.