How can you tell if a value is not numeric in Oracle?

前端 未结 6 1196
渐次进展
渐次进展 2020-11-27 05:37

I have the following code that returns an error message if my value is invalid. I would like to give the same error message if the value given is not numeric.



        
6条回答
  •  萌比男神i
    2020-11-27 06:08

    From Oracle DB 12c Release 2 you could use VALIDATE_CONVERSION function:

    VALIDATE_CONVERSION determines whether expr can be converted to the specified data type. If expr can be successfully converted, then this function returns 1; otherwise, this function returns 0. If expr evaluates to null, then this function returns 1. If an error occurs while evaluating expr, then this function returns the error.

     IF (VALIDATE_CONVERSION(value AS NUMBER) = 1) THEN
         ...
     END IF;
    

    db<>fiddle demo

提交回复
热议问题