declare
  vXH VARCHAR2(12); select xh into vXH from table1 where xh = '020001'; 当有xh = '020001'这条记录时,可以正常运行
当没有xh = '020001' 这条记录时就会出错通常是先判断 select count(*) from table1 where xh = '020001'; 如果不用count,该如果写呢?

解决方案 »

  1.   

    因为如果不加条件时,会select出多个值啊,所以赋值时会报错。不用count的话就加个条件where rownum=1
      

  2.   

    select 
      xh ,
      count('x')
    into 
      vXH ,
      cnt
    from table1 where xh = '020001';  这样的话,即使查不到数据(cnt = 0),程序也不会报错
      

  3.   

    忘记说清楚了, xh字段是关键字段,只存在一条记录或没有记录的情况。
    现在是怎么处理没有数据的情况,能否不用count来判断呢?
      

  4.   

    好像执行不走,报错:not a single-group group function
      

  5.   

    忘了  给后面加group by xh
      

  6.   

    select count(*) from table1 where xh='020001' and rownum=1;