PL / SQLのSQLのカーソル

1.文法1 [基本的なカーソル形式]

--创建游标
cursor 游标名称 is sql语句
--打开游标
open 游标名称;
--遍历的数据存放到emprow记录型变量,fetch获取游标的数据
fetch cl into emprow;
--查询没有数据
%notfound

2.例

写真

3.構文2 [パラメーター付きのカーソル形式]

declare
  cursor cl2(eno emp.deptno%type)--对游标中存储的指定的参数进行数据类型设置
  is select empno from emp where deptno = eno;
  
  en emp.empno%type;
begin
  open cl2(10);--获取游标中指定参数的数据,需要打开游标时进行声明
       loop
         fetch cl2 into en;--读取游标的数据存放在
         exit when cl2%notfound;--设置退出循环条件
         update emp set sal=sal+100 where empno = en;--设置更新sql语句
         commit;--增删改需要进行事务提交
       end loop;
  close cl2;
end;

4.例

写真

公開された62元の記事 ウォン称賛20 ビュー6775

おすすめ

転載: blog.csdn.net/qq_45421186/article/details/105464012
おすすめ