oracle教程:游标

要点:
游标是系统为用户开设的一个数据缓冲区,存放SQL语句的执行结果。我们可以把游标理解为PL/SQL中的结果集。

创建游标后面跟着sql语句,然后打开游标、循环游标的内容直到游标内容循环结束。关闭游标。

 --需求:打印业主类型为 1 的价格表

 declare

   cursor cur_pricetable is select  from t_pricetable where ownertypeid=1;--声明游标

   v_pricetable t_pricetable%rowtype;

 begin

   open cur_pricetable;--打开游标

   loop

     fetch cur_pricetable into v_pricetable;--提取游标

     exit when cur_pricetable%notfound;--退出循环游标

     dbms_output.put_line('价格:'||v_pricetable.price||

     ' 吨位:'||v_pricetable.minnum||'-'||v_pricetable.maxnum);

   end loop;

   close cur_pricetable;--关闭游标

 end;

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/a772304419/article/details/132479421