Links

   Quran Explorer - Interactive Audio Recitations & Translations

Thursday, June 13, 2013

Oracle isNumeric function



AFAIK there is no in-built function to do such but there are lots of ways to achieve the same using the functions already available.

Here is a list of some;

Option 1: Using to_number()
Attempt to convert the input/variable to a anumber.. if it succeeds then isNumeric is true otherwise false

CREATE OR REPLACE FUNCTION isNumeric (var in varchar) return char is
   dummy number;
begin
     select to_number(trim(var)) into dummy from dual; 
   if (dummy is null) then
      return '0';
   else
      return '1';
  end if;  
exception
   when others then
       return '0';
end;
/

Option 2: Using regex

No comments:

Post a Comment

Feel free to leave a comment