check if “it's a number” function in Oracle

后端 未结 16 2770
一整个雨季
一整个雨季 2020-11-28 10:31

I\'m trying to check if a value from a column in an oracle (10g) query is a number in order to compare it. Something like:

select case when ( is_number(myTab         


        
16条回答
  •  执念已碎
    2020-11-28 11:08

    @JustinCave - The "when value_error" replacement for "when others" is a nice refinement to your approach above. This slight additional tweak, while conceptually the same, removes the requirement for the definition of and consequent memory allocation to your l_num variable:

    function validNumber(vSomeValue IN varchar2)
         return varchar2 DETERMINISTIC PARALLEL_ENABLE
         is
    begin
      return case when abs(vSomeValue) >= 0 then 'T' end;
    exception
      when value_error then
        return 'F';
    end;
    

    Just a note also to anyone preferring to emulate Oracle number format logic using the "riskier" REGEXP approach, please don't forget to consider NLS_NUMERIC_CHARACTERS and NLS_TERRITORY.

提交回复
热议问题