我想查出
select * from aaa where
 is_number(a)='Y' and  to_number(a)>1 
就是想求出 这个列是数字 并且大于1的
可这样就是报无效数字,is_number()已经把不是数字的过滤掉了啊 还报错is_number() 是函数
BEGIN
  v_string := TO_NUMBER (p_string);
  RETURN 'Y';
EXCEPTION
  WHEN VALUE_ERROR THEN
  RETURN 'N';

解决方案 »

  1.   

    报错的是后面的to_number(a)>1
      

  2.   

    这样就不报错了
    select * from
    (select * from aaa where is_number(a)='Y') 
    where to_number(a)>1;
      

  3.   

     用系统定义的函数ISNUMERIC().
     条件ISNUMERIC(a)=1 and a>1.
      

  4.   

    ()扩起来还是还报错  ISNUMERIC  没有这个函数
      

  5.   

    试了试,发现一个奇怪的现象
    SQL> create table test (t varchar2(10));表已创建。SQL> insert into test values('1');已创建 1 行。SQL> insert into test values('2');已创建 1 行。SQL> insert into test values('383');已创建 1 行。SQL> insert into test values('a1');已创建 1 行。SQL> commit;提交完成。SQL> ed
    已写入文件 afiedt.buf  1  create or replace function is_number(p_string in varchar2) return varchar2
      2  as
      3  v_string number;
      4  BEGIN
      5    v_string := TO_NUMBER (p_string);
      6    RETURN 'Y';
      7  EXCEPTION
      8    WHEN VALUE_ERROR THEN
      9    RETURN 'N';
     10* end;
    SQL> /函数已创建。SQL> select * from test where to_number(t)>1;
    ERROR:
    ORA-01722: invalid number未选定行SQL> select * from test where is_number(t)='Y' and to_number(t)>1;
    ERROR:
    ORA-01722: invalid number未选定行SQL> select * from (select * from test where is_number(t)='Y') a where to_number(a.t)>1;
    ERROR:
    ORA-01722: invalid number未选定行--前面几个sql都是报的一样的错,可下面这句报的错误不一样
    SQL> select * from (select * from test where t in (select t from test where is_number(t)='Y')) where
     to_number(t)>1;
    select * from (select * from test where t in (select t from test where is_number(t)='Y')) where to_n
                                                                                                    *
    ERROR 位于第1行:
    ORA-01722: invalid number