1.CREATE OR REPLACE PROCEDURE cur_exp_1 IS
   CURSOR c1 IS
      SELECT emp_id, dept_name
        FROM emp, dept
       WHERE dept.location = 'London'
         AND dept.dept_id = emp.dept_id;
   TYPE rec_type IS RECORD (id   emp.emp_id%TYPE,
                            name dept.dept_name%TYPE); 
   rec rec_type;
BEGIN
   OPEN c1;
   LOOP
      FETCH c1 INTO rec;
      EXIT WHEN c1%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE(rec.id);
   END LLOP;
   CLOSE c1;
END;2. A

解决方案 »

  1.   

    我刚学,对第一题有个框架,
    declare
    cursor mycursor
    begin
     loop
    fetch mycursor into
    exit when mycursor%not found
    if...
      then...
    else...
    end if..
    end loop
    close mycursor;
    end.
    这个是老师给的框架.能帮我补全么?顺便讲一下,谢谢:)
      

  2.   

    declare
    cursor mycursor
    select * from tabname;
    begin
    open mycusor;
    loop
    fetch mycursor into 变量;
    exit when mycursor%notfound;
    if...then
    ...
    else
    ...
    end if;
    end loop;
    close mycursor;
    end;
    /
      

  3.   

    没有必要补全,省略号应该是你要实现的业务
    比如 变量s_tabname类型为tabname%rowtype,其中有一个字段为owner,并定义一个变量count,
    s_tabname tabname%rowtype;
    count integer(4) :=0;
    则:
    IF s_tabname.owner='SYSTEM' THEN 
    COUNT:=COUNT+1;
    END IF;
      

  4.   

    declare @i
    create table #tmp
    (id indentiy(1,1) not null,
     a ... 
     ..
     .)
    insert #tmp(a..,..)
    from targetTablewhere (1=1)begin
    select @i=(select max(id ) from #tmp)
    if isnull(@i) 
     break
    --your action--delete #tmp
    where #tmp.id=@i
    end
      

  5.   

    其实我觉得第一个例子就已经说明了游标的基本用法。以学生信息为例,显示学生的姓名的学号:
    set serverout on
    declare
    cursor stu_cursor is 
      select stuno,stuname from student order by stuno;
    stu_record stu_cursor%rowtype;
    -------定义一个变量,和游标的字段相对应
    open stu_cursor;
    loop
      fetch stu_cursor into stu_record;
    exit when stu_cursor%notfound;
      dbms_output.put_line(stu_record.stuno);
      dbms_output.put_line(stu_record.stuname);
    end loop;
    close stu_cursor;
    end;对于数值类型,可以使用number(*,n),n是小数点后面的位数。