今天用pl/sql developer查询时出错了。sql语句如下:
select t.* from t_user_test t where t.t_dept = 48000148400 and t.t_user=790000561;
报‘无效数字’错误,把 and t.t_user=790000561 去掉就能查询出来,把790000561改成‘790000561’也能查询出来。
那个t_dept和t_user都是varchar2(100)类型的,怎么t_dept就没错?搞不懂为什么。

解决方案 »

  1.   

    t_user_test 表中 t_user 字段里包含有非数字的值,所以报错
    而 t_dept 的值都是数字型的,所以不报错
      

  2.   


    SQL> create table test1(id        varchar2(200));
     
    Table created
    SQL> insert into test1 values('1');
     
    1 row inserted
    SQL> commit;
     
    Commit complete
    SQL> select * from test1 where id = 1;
     
    ID
    --------------------------------------------------------------------------------
    1
    SQL> insert into test1 values('-');
     
    1 row inserted
    SQL> commit;
     
    Commit complete
    SQL> select * from test1 where id = 1;
     
    select * from test1 where id = 1
     
    ORA-01722: 无效数字
      

  3.   

    楼上正解select t.* from t_user_test t where t.t_dept = '48000148400' and t.t_user='790000561';这样就不会报错了。
    在解析sql时,如果是写为t_dept = 48000148400,它会默认将t_dept转型为数字,然后进行比对。
    故报出如题述错误。