求用一条SQL语句判断一个字符串是否是数字的办法
现在大家都是用函数的方式来判断一个字符串是否是数字,但是现在有没有只用一条SQL语句就能判断字符串是否是数字呢?有的话请各位大侠不吝赐教,谢谢

解决方案 »

  1.   

    var info varchar2(100);
    declare
       dummy_   number;
    begin
       select to_number('&string') into dummy_ from dual;
       :info := 'Is a number string!';
       dbms_output.put_line('Is a number string!');
       
    EXCEPTION
       WHEN others THEN
          :info := 'Is not a number string!';
          dbms_output.put_line('Is not a number string!');
    end;
    /
      

  2.   

    you can try this    select 1 from dual where ltrim(&a,'0123456789') is null;
      

  3.   

    10g可以用正则表达式的方法
    select REGEXP_LIKE(字段, [[:digit:]] ) from dual;
      

  4.   

    留几个测试的例子:SQL> select 1+1 from dual where REGEXP_LIKE(123, '[[:digit:]]') ;       1+1
    ----------
             2SQL> select 1+1 from dual where REGEXP_LIKE('aaa', '[[:digit:]]') ;no rows selectedSQL> select 1+1 from dual where REGEXP_LIKE('222', '[[:digit:]]') ;       1+1
    ----------
             2
      

  5.   

    select to_number('222') from dual;能够转换,但是不能判断
      

  6.   

    select * from(
    select '1' as str from dual union
    select '1.1' from dual union
    select '1.a' from dual union
    select '-6.0' from dual union
    select '+6.0'from dual union
    select '.9'from dual) a
    where NVL(TRANSLATE (str, '.0123456789', '.'),'.') in('+.','-.','.')   
    /*
    STR
    +6.0
    -6.0
    .9
    1
    1.1*/
      

  7.   

    就按照5楼的做了。 如果你的不幸是10g以下。那就不要判断了,出了异常再处理,更节省时间。
    也许oracle以后会写个函数is_number ,或者自己写个也行啊。
      

  8.   

    以前写过一个,和这个差不多;那时oracle版本比较老
    如果是10g,还是用正则表达式吧
      

  9.   

    --测试数据
    ID       RMAK
    ------------------
    21 litt1232dd
    9 litt1232
    23 tom
    21 125delitt1232
    9 ggg
    10 123--SQL语句
    SELECT * from a where translate(lower(rmak),'0123456789','0000000000')=rpad('0',length(rmak),'0');--执行结果只显示是数字的行
    ID       RMAK
    -----------------
    10 123
      

  10.   

    我觉得用to_number 是一种方式正则表达式还没有用过