Search notes:

Test for function IS_NUMBER of PL/SQL package TXT

This is a test case for the function is_number of the PL/SQL package txt.
declare

  procedure test_str(str varchar2, expected boolean) is
  begin

    if txt.is_number(str) != expected then
       dbms_output.put_line('Wrong expectation for >' || str || '<');
    end if;

  end test_str;

begin

-- numbers
   test_str( '42'    , true);
   test_str( '42.42' , true);
   test_str('-42'    , true);
   test_str('-42.42' , true);
   test_str('4.249E6', true);

-- leading spaces:
   test_str('     42'     , true);
   test_str('     42.42'  , true);
   test_str('    -42'     , true);
   test_str('    -42.42'  , true);
   test_str('  4.249E6'   , true);

-- leading + trailing spaces:
   test_str('     42     ', true);
   test_str('     42.42  ', true);
   test_str('    -42     ', true);
   test_str('    -42.42  ', true);
   test_str('  4.249E6   ', true);

   test_str('foo'         , false);

end;
/
Github repository PL-SQL-pkg-txt, path: /_test/is_number.sql

See also

Consider using the SQL function validate_conversion instead of txt.is_number.
ORA-01722: invalid number

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758206668, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/PL-SQL/libs/personal/txt/_test/is_number(81): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78