我按照如下方式建立游标:
declare 
    tempsal scott.emp.sal%type;
    cursor mycursor is
        select * from scott.emp
        where sal>tempsal;
    cursorrecord mycursor%rowtype;
begin
    tempsal := 800;
    open mycursor;
    fetch mycursor into cursorrecord;
    dbms_output.put_line(to_char(cursorrecord.deptno));
end;
那么如何运行这个游标。
我在SQL中运行该程序,提示“PL/SQL 过程已成功完成。”
那么我该如何运行这个过程,游标能起到什么作用?它是干什么的?

解决方案 »

  1.   

    sql> set serveroutput on -- 然后,在执行上面的代码
      

  2.   

    set serveroutput on mycursor;
    不能呀,主要是我现在不知道游标能干什么?
    如何使用,在我看来,它是不是可以就象可执行程序那样,运行一个执行文件,出来一个结果。
      

  3.   

    sql> set serveroutput on
    sql>declare 
        tempsal scott.emp.sal%type;
        cursor mycursor is
            select * from scott.emp
            where sal>tempsal;
        cursorrecord mycursor%rowtype;
    begin
        tempsal := 800;
        open mycursor;
        fetch mycursor into cursorrecord;
        dbms_output.put_line(to_char(cursorrecord.deptno));
    end;
    游标 : 相当于c++ 中的指针的概念,使用它可以检索记录。
           仅此而已。
      

  4.   

    SQL> select * from a;     VALUE VALUE_DATE  ID
    ---------- ----------- ----------
            10 2004-1-7 18 1
            10 2004-1-7 18 2
            10 2004-1-7 18 3
            20 2004-1-7 18 SQL> set serveroutput on
    SQL> 
    SQL> declare
      2  cursor t_sor is
      3  select * from a;
      4  sor t_sor%rowtype;
      5  begin
      6    open t_sor;
      7    fetch t_sor into sor;
      8    loop
      9    exit when t_sor%notfound;
     10    dbms_output.put_line(sor.value);
     11    fetch t_sor into sor;
     12    end loop;
     13    close t_sor;
     14  end;
     15  /
    10
    10
    10
    20PL/SQL procedure successfully completed游标起到查询作用
      

  5.   

    游标的打开方式有两种:显式和隐式
    显式:open NoticeStaffInfos;  需要显式的关闭!close NoticeStaffInfos; 
    隐式: for NoitceInfo in NoticeStaffInfos Loop 使用完系统自动关闭!open NoticeStaffInfos;
    for NoitceInfo in NoticeStaffInfos Loop
    这两个都是打开游标的方式,只采用一个即可。