declare
v_result number(80);
begin
  for cur in (select distinct no from table )
  loop
    v_result:=cur.no;
    dbms_output.put_line('工号为'||v_result);
  end loop;
end ;
大家帮忙看看这有没有错误就是把所有的员工工号打出来!

解决方案 »

  1.   

    语法没问题,就是number(80)太夸张,一我用的最大才number(19),80位是什么概念
      

  2.   

    建议还是把程序写的规范点吧:(别打我啊)declare
      v_result number(80);
      CURSOR curs is
        select distinct no from table;
    begin
      for c_cur in curs loop  
        v_result:=cur.no;
        dbms_output.put_line('工号为:'||to_char(v_result));
      end loop;
    exception
      when others then
        dbms_output.put_line(substr(sqlerrm,1,255));
    end ;
      

  3.   

    代码本身没问题,注意:你使用的游标,oracle 有超时的问题...