我想把某一字段不为空的记录找出来,有以下SQL语句:
select buyDate as 购买日期, IC_number as 会员卡号 from tableName where IC_number is not null 按以上语句,应是会员卡号不为空的记录才会显示出来,但现在显示的结果却夹杂着几条IC_number为空的记录。我已检查为空的那几条记录IC_nubmer列什么也没有,包括' '.
请问各位大虾是什么原因呢?我该如何让那几样为空的也不显示出来?
我用的版本是oracle 10g。
先谢了!

解决方案 »

  1.   

    select buyDate as 购买日期, IC_number as 会员卡号 from tableName 
    where (IC_number is not null) and (trim(IC_number) <> '')则没有找到任何一条记录。
      

  2.   

    有点怪。我刚试了我自己的,SQL 语句没有问题。
    不过我的版本是11g的。PL/SQL是7.11
      

  3.   

    是不是跟PL/SQL也有关啊,我的PL/SQL是7.1.4
      

  4.   

    select buyDate as 购买日期, IC_number as 会员卡号 from tableName where IC_number>0;
    如果是字符串就
    select buyDate as 购买日期, IC_number as 会员卡号 from tableName where IC_number>'0';
      

  5.   

    ----------------------------------------------------
    是字符串,用 where IC_number>'0',空的记录还是会出来。
      

  6.   

    select buyDate as 购买日期, IC_number as 会员卡号 from tableName 
    where (trim(IC_number) <> '')这样试下。
      

  7.   

    ----------------------------------------------------
    是字符串,用 where IC_number>'0',空的记录还是会出来。可是这个语句我真的在我这儿测试过,可以的。你不妨先把那个为空的记录字段update为null,再试试
      

  8.   

    ---------------------------------------
    请看图,倒数第二条便是。
    你都把 is not null 条件注释掉了?
      

  9.   

    你上面会是有空格,回车或换行符,你用chr(9)等逐个的试试看看,一定不都是空格
      

  10.   


    select buyDate as 购买日期, IC_number as 会员卡号 from tableName 
    where (IC_number is not null) and (trim(IC_number) <> '')则没有找到任何一条记录。select buyDate as 购买日期, IC_number as 会员卡号 from tableName 
    where trim(IC_number) is not null
      

  11.   

    这种可能是有回车换行符引起的。UPDATE吧
      

  12.   

    参考下面示例就可了解:create table scott.dfs(v_name varchar2(50));
    insert into scott.dfs values(chr(10)||chr(13));
    commit;
    select * from scott.dfs where v_name is not null;
      

  13.   

    參考17樓,点开字段的值,看一下是否有回车或换行!!!select buyDate as 购买日期, IC_number as 会员卡号 from tableName where length(trim(IC_number))>=6
      

  14.   

    --------------------------------------------
    会不会跟我用 left join 有关呢?见我上面的图。
    谢谢!
      

  15.   

    我也感觉会不会跟使用了left join有关
      

  16.   

    如果不使用LEFT JOIN , 单独查其中一个表是不会有记录出来的。郁闷...
      

  17.   

    用ascii(IC_number) 看下返回如何
      

  18.   

    楼主,换成
    ass_number is not null
    试试。
    因为left join后,表里面已经没有ls_ic_number列了。
      

  19.   


    已经用过 is not null了。还是不行。
      

  20.   


    已经用过 is not null了。还是不行。LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。所以,应该添加ass_number is not null 的判断条件。注意,这里是 ass ,不是 ls 了。
      

  21.   

    最简单的办法,换成这种查询条件吧:select * from ls_fs a, sys_associator b where a.ls_ic_number = b.ass_number and .......
      

  22.   

    估计是字段值中有特殊符号,试试IC_number>=' ',空格是可视字符ascii码最小的
      

  23.   

    真理啊,话说楼主sql字段的所属表别名都不加,太有歧义了。逻辑上的分析楼上都说全了,还是不对的话,那就是数据导入有问题,或者表结构字段类型问题。建议另外建两个模拟测试表,手工加几条数据,试一下。
      

  24.   

    我也认为是left join的关系。
      

  25.   

    跟left join 有什么关系。。还是感觉特殊字符引起的。。