select t1,t2 into m1,m2 
from result1
where t1=(select min(t1) from result1);

解决方案 »

  1.   

    那怎么判断result1表是否为空呢?
      

  2.   

    select t1,t2 into m1,m2 
    from result1
    where t1=(select min(t1) from result1) and exists (select 1 from result1);
      

  3.   

    select t1,t2,count(*) into m1,m2,l_count 
    from result1
    where t1=(select min(t1) from result1)
    group by t1,t2;l_count是个变量
    if l_count = 0 then
       -- 退出程序
       return;
    end if;
      

  4.   

    to lastdrop:
    我照您的方案,但是sql*plus提示出错:
    ERROR 位于第 1 行:
    ORA-00937: 非单组分组函数
    ORA-06512: 在"SYS.PROC_CHECKSECOND", line 62
    ORA-06512: 在"SYS.PROC_INITBEGINENDADDRESS", line 62
    ORA-06512: 在line 5
    我估计是group by 的问题,请帮忙!!
      

  5.   

    declare
    m1 result1.t1%type;
    m2 result1.t2%type;
    begin
    for i in (select count(1) con from result1) loop
    if i.con>0 then
    select t1,t2 into m1,m2 
    from result1
    where t1=(select min(t1) from result1)
    end if;
    end loop;
    end;
    /
      

  6.   

    to: hhdn(想高飞的小小鸟) 
    你确认你的SQL中,除count(*)外的字段都出现在了group by 子句中吗?如果问题还出现,贴出你的代码瞧瞧。
      

  7.   

    有一个表:tb_result1_temp
    creat table tb_result1_temp
    (check_count number(1),
    bus_stop_count number(5),
    bus_begin_name varchar2(20),
    bus_begin_stop varchar2(20),
    bus_change1_stop varchar2(20),
    bus_change1_name varchar2(20),
    bus_end_stop varchar2(20));表中有值:
    insert into tb_result1_temp values(1,5,'86路','农业大学','工大','78路'
    ,'秋林公司');
    insert into tb_result1_temp values(1,8,'21路','农业大学','博物馆','103路'
    ,'秋林公司');我在运行下列pl/sql块时遇到问题:
    declare
    i_check_count number(1) := 0;
    i_busstop_count number(5) :=0;
    i_initmid2_name varchar2(20);
    i_initmid2_stop varchar2(20);
    i_change1_stop varchar2(20);
    i_change1_name varchar2(20);
    i_end_stop varchar2(20);
    v_result1_rowcount number(5);
    begin
    select 
    check_count,
    bus_stop_count,
    bus_begin_name,
    bus_begin_stop,
    bus_change1_stop,
    bus_change1_name,
    bus_end_stop,
    count(*)
    into
    i_check_count,
    i_busstop_count,
    i_initmid2_name,
    i_initmid2_stop,
    i_change1_stop,
    i_change1_name,
    i_end_stop,
    v_result1_rowcount
    from tb_result1_temp
    where bus_stop_count=(select min(bus_stop_count) from tb_reslut1_temp)
    order by bus_stop_count;
    end;
      

  8.   

    错误为:
    ora-00917:非单组分组函数
    而把order改为group后出错:
    ora-00979:不是group by表达式
    而在where后什么也不加后出错:
    ora-00917:非单组分组函数
    请帮忙改正!!!
      

  9.   

    在where bus_stop_count=(select min(bus_stop_count) from tb_reslut1_temp)
    后加
    group by bus_stop_count, bus_begin_name, bus_begin_stop, bus_change1_stop, bus_change1_name, bus_end_stop没想到你有这么多字段,你也可以用exception
    declare
    i_check_count number(1) := 0;
    i_busstop_count number(5) :=0;
    i_initmid2_name varchar2(20);
    i_initmid2_stop varchar2(20);
    i_change1_stop varchar2(20);
    i_change1_name varchar2(20);
    i_end_stop varchar2(20);
    v_result1_rowcount number(5);
    begin
    select 
    check_count,
    bus_stop_count,
    bus_begin_name,
    bus_begin_stop,
    bus_change1_stop,
    bus_change1_name,
    bus_end_stop
    into
    i_check_count,
    i_busstop_count,
    i_initmid2_name,
    i_initmid2_stop,
    i_change1_stop,
    i_change1_name,
    i_end_stop
    from tb_result1_temp
    where bus_stop_count=(select min(bus_stop_count) from tb_reslut1_temp)
    order by bus_stop_count;exception
      when no_data_found then --没有记录
           .. 
    end;
    /还有select into应该只可以选出一条记录,order by是没有意义的。
      

  10.   

    谢谢大家的热心帮助,我已经解决了这个问题,
    group by 后应加上所以得select里的列名。
    谢谢各位的帮忙!!!