游标的使用例子如下:一般在存储过程中
cursor cur_test is select ****(列) from tab_name where ***;--打开游标
if not cur_test%ISOPEN then
   open cur_test;
end if;--循环使用游标取出来的数据
loop
 fetch cur_test into 变量;
 exit when cur_test%NOTFOUND;
 ......
end loop;
close cur_test;  --关闭

解决方案 »

  1.   

    打个不恰当的比方,把游标看作数组,用select语句,将数据从表里取出放到游标中,然后在用fetch into将其中的值赋给变量,献丑了
      

  2.   

    游标主要为了查询,其实与编程语言recordset作用相同
      

  3.   

    我现在有一个表,请问可以给个例子吗?说明显示和隐示的用法和区别,谢谢.
    SQL> desc customer;
     名称                                      是否为空? 类型
     ----------------------------------------- -------- --------------
     LAST_NAME                                 NOT NULL VARCHAR2(30)
     STATE_CD                                           VARCHAR2(2)
     SALES                                              NUMBERSQL> select * from customer;LAST_NAME                      ST      SALES
    ------------------------------ -- ----------
    Nicholson                      ca    6989.99
    gdy                            gd      99999
    martin                         ca    2345.45
    Laursen                        CA      34.34
    bambi                          ca    1234.55
    mcgraw                         nj     123.45已选择6行。 beckhambobo(beckham)很可惜我不会编程
     kerisyml(魂之利刃) 你给的例子书里更详细,可是可能因为我没书的环境,怎么试也不成功,所以希望有个成功的使用例子.
    lianhg(lianhg)我明白,可还是不成功.例如如下的写法.
    SQL> declare
      2  lname varchar2(30);
      3  ls number;
      4  cursor cur_customer is
      5  select name,sales from customer where sales=1000;
      6  begin
      7  open cur_customer;
      8  fetch cur_customer into lname, ls;
      9  close cur_customer;
     10  /
      

  4.   

    1  declare
      2  lname varchar2(10);
      3  ls number;
      4  cursor mycursor is select loginid from customer where userid=1502;
      5  begin
      6  open mycursor;
      7  fetch mycursor into lname;
      8  dbms_output.put_line(lname);
      9  close mycursor;
     10* end;
    SQL> /
    mjb01PL/SQL procedure successfully completed.SQL>
      

  5.   

    1  declare
      2  lname varchar2(10);
      3  ls number;
      4  cursor mycursor is select loginid,userid from customer where userid=1502;
      5  begin
      6  open mycursor;
      7  fetch mycursor into lname,ls;
      8  dbms_output.put_line(lname||','||ls);
      9  close mycursor;
     10* end;
    SQL> /
    mjb01,1502PL/SQL procedure successfully completed.SQL>
      

  6.   

    7  fetch mycursor into lname;
      8  dbms_output.put_line(lname);
    第二句我不明白.如果这不这样用还能怎样用?
      

  7.   

    dbms_output.put_line(lname);
    作用只是为了打印出fetch的结果而以!