从几个表中选取n个字段到游标中,
然后对游标中的几个字段进行分别处理,
然后输出处理后的游标例如:
 
   
begin   
  open result for select a.speed from table1 a;   
  for r_result in result loop       
         result.speed:=result.speed+100;   (这儿改怎末写)
  end loop;   
end;

解决方案 »

  1.   

    Example 6-41 Using CURRENT OF to Update the Latest Row Fetched From a CursorDECLARE
       my_emp_id NUMBER(6);
       my_job_id VARCHAR2(10);
       my_sal    NUMBER(8,2);
       CURSOR c1 IS SELECT employee_id, job_id, salary FROM employees FOR UPDATE;
    BEGIN
       OPEN c1;
       LOOP
          FETCH c1 INTO my_emp_id, my_job_id, my_sal;
          IF my_job_id = 'SA_REP' THEN
            UPDATE employees SET salary = salary * 1.02 WHERE CURRENT OF c1;
          END IF;
          EXIT WHEN c1%NOTFOUND;
       END LOOP;
    END;
    /
      

  2.   

    或者在cursor里引用rowid,使用rowid实现更新.
    oracle的CURRENT OF也是基于rowid实现的
      

  3.   

    游标是用来读的不是用来修改的
    你可以把游标里的数据提出来存入一个表变量,然后对其进行更改
    要改很多,想在oracle的cursor中改完了后,一次输出
    有其他好办法吗
      

  4.   

    minitoy:
    要改很多,想在oracle的cursor中改完了后,一次输出
    有其他好办法吗
      

  5.   

    在为什么不在cursor的select语句中实现呢?
      

  6.   

    delcare
    cursor cur1 is select a.speed from table1 a for update; 
    v_col tb.speed%type;
    begin
    open cur1;
    fetch cur1 into v_col;
    while cur1%found loop
    update tbb set col2='...' where current of cur1;
    fetch cur1 into v_col;
    end loop;
    close cur1;
    end;
      

  7.   

    elcare
    cursor cur1 is select a.speed from table1 a for update;  
    v_col tb.speed%type;
    begin
    open cur1;
    fetch cur1 into v_col;
    while cur1%found loop
    update tbb set col2='...' where current of cur1;
    fetch cur1 into v_col;
    end loop;
    close cur1;
    end;声明游标时候的for update,理论上是需要有的,但实际上可以不写。