请问个问题
select nvl(cy4,'空的') from cl_cy where SEQNO = '0066722';
--返回正常
select nvl(cy4,'空的') from cl_cy ta,person tb where ta.SEQNO = '0066722' and ta.cy4=tb.usercode;
--返回不正常

解决方案 »

  1.   

    你的语句根本不通嘛。SELECT NVL (cy4, '空的')
      FROM cl_cy ta, person tb
     WHERE ta.seqno = '0066722 ' AND ta.cy4 = tb.usercode;
    --                               ta.cy4 = tb.usercode保证了cy4肯定不为空,那肯定不会需要使用nvl(cy4,'空的')咯
      

  2.   

    select nvl(cy4, '空的 ') from cl_cy ta,person tb where ta.SEQNO =  '0066722 ' and ta.cy4=tb.usercode; 嗬嗬,你的条件ta.cy4=tb.usercode,
    两个表等价连接。
    只有都满足的记录才会选出来,LZ是不是对表的联结的理解有问题呢?
    想要cl_cy ta里面的所有数据都显示出来,需要用到左完全外连接。
      

  3.   

    个人觉得问题在于,select的项目没有制定表名。
    改成select nvl(ta.cy4,  '空的  ')试一下。
      

  4.   

    to kidman_ray:
    假如他的两个表都有cy4的话,sql就是报错的,说这个字段暧昧。
      

  5.   

    如果cy4==null,则ta.cy4=tb.usercode;为false你的查询不会返回cy4==null的纪录
      

  6.   

    左外连接,或者直接加点东西,
    select   nvl(cy4, '空的')   from   cl_cy   ta,person   tb   
    where   ta.SEQNO   =   '0066722'   
    and   (ta.cy4=tb.usercode or ta.cy4 is null); 
      

  7.   

    你的意图可能写得不是很清楚,你试试这下面语句能得到你的结果不:
    select   nvl(cy4, '空的') from   cl_cy   ta,person   tb   where   ta.SEQNO   =   '0066722'  and   ta.cy4=tb.usercode(+); 
    或者
    select   nvl(cy4, '空的') from   cl_cy   ta,person   tb   where   ta.SEQNO   =   '0066722'  and   ta.cy4=tb.usercode(+); 
      

  8.   

    怯怯地问句
     nvl(cy4, '空的 ')什么意思?