给你个简单的:declare
begin
  FOR C1 IN (select a.city_name, a.location, b.temp_hi, b.temp_lo
               from city a
               left join weather b
                 on a.city_name = b.city_name) LOOP
  
    insert into city_weather
      (city_name, location, hi_temp, lo_temp)
    values
      (C1.Yname, C1.location, C1.temp_hi, C1.temp_lo);
  END LOOP;
end;

解决方案 »

  1.   

    1、楼主注意显式游标的使用顺序。
    2、type t_StudnetsRef is ref cursor return studnets%rowtype
     t_StudnetsRef只是定义一个游标类型 使用的时候 用c_student  t_StudnetsRef;声明c_student游标。
     studnets%rowtype students表数据行类型
     
      

  2.   

    给你个简单的:declare
    begin
      FOR C1 IN (select a.city_name, a.location, b.temp_hi, b.temp_lo
                   from city a
                   left join weather b
                     on a.city_name = b.city_name) LOOP
      
        insert into city_weather
          (city_name, location, hi_temp, lo_temp)
        values
          (C1.Yname, C1.location, C1.temp_hi, C1.temp_lo);
      END LOOP;
    end;这是只是实现操作的话,我直接用create table as了,只是学习到游标这一块有很多疑问,我之前的语句为什么运行没有结果呢,4楼的大大说要注意显示游标的使用顺序????我的顺序错了么??还有就是关于游标变量的命名,返回数据类型中为什么要加入表名?%rowtype不就已经是数据类型了么,前边加上student难道只能使用该表么?最后就是回到第一个问题了,游标到底有什么优势呢,好多操作都可以用其他跟简单的形式完成,所以对游标很迷惑
      

  3.   

    1.针对你的例子写了个一个EXAMPLE(fetch应该在loop里):
    declare
      l_fndid varchar2(20);
      cursor YB is
        select fnd_id from tgp_funds a;
    begin
      open YB;
      loop
        fetch YB
          into l_fndid;
        exit when YB%notfound;
        dbms_output.put_line(l_fndid);
      end loop;
      close YB;
    end;2.当你一个游标返回的是一个表的一行数据时,你可以定义一个rowtype来获取数据,这样的好处是如果返回的字段很多,就不用定义全部字段,当然如果你返回的是多个表的字段,你可以定义一个type来获取字段如:
    declare
      l_fndid varchar2(20);
      cursor YB is
        select * from tgp_funds a;
      fnd_rec tgp_funds%rowtype;
    begin
      open YB;
      loop
        fetch YB
          into fnd_rec;
        exit when YB%notfound;
        dbms_output.put_line(fnd_rec.fnd_id || fnd_rec.fnd_vers);
      end loop;
      close YB;
    end;3.游标的优势在于它可以同时获取多个字段或者一个结果集。你还可以在网上看看动态游标,更灵活
      

  4.   

    1.针对你的例子写了个一个EXAMPLE(fetch应该在loop里):
    declare
      l_fndid varchar2(20);
      cursor YB is
        select fnd_id from tgp_funds a;
    begin
      open YB;
      loop
        fetch YB
          into l_fndid;
        exit when YB%notfound;
        dbms_output.put_line(l_fndid);
      end loop;
      close YB;
    end;2.当你一个游标返回的是一个表的一行数据时,你可以定义一个rowtype来获取数据,这样的好处是如果返回的字段很多,就不用定义全部字段,当然如果你返回的是多个表的字段,你可以定义一个type来获取字段如:
    declare
      l_fndid varchar2(20);
      cursor YB is
        select * from tgp_funds a;
      fnd_rec tgp_funds%rowtype;
    begin
      open YB;
      loop
        fetch YB
          into fnd_rec;
        exit when YB%notfound;
        dbms_output.put_line(fnd_rec.fnd_id || fnd_rec.fnd_vers);
      end loop;
      close YB;
    end;3.游标的优势在于它可以同时获取多个字段或者一个结果集。你还可以在网上看看动态游标,更灵活多谢版主的耐心指导,自学oracle有好多地方都很迷惑,这下关于静态游标就清楚了,之前语句的确是顺序错了,马上去自学研究研究动态游标~谢谢各位的指导~