首页 > 代码库 > Oracle 游标

Oracle 游标

1:方式一

declare     
       cursor c_job is select real_name,user_name,id from ram_user;--游标也是变量
       c_row c_job%rowtype; --定义一个游标变量c_row ,该类型为游标c_job中的一行数据类型
       v_result int;
begin
       for c_row in c_job loop          
            select count(*) into v_result from ram_user_role where user_id = c_row.id;
            if v_result < 1 then
          -- dbms_output.put_line(‘sssssssss‘);
               dbms_output.put_line(c_row.real_name || ‘:‘ || c_row.user_name);
            end if;
       end loop;
end;

2:方式二

declare        
cursor c_job is select empno,ename,job,sal from emp where job=MANAGER‘;--类型定义
c_row c_job%rowtype;--定义一个游标变量
begin
open c_job;
loop
fetch c_job into c_row; --提取一行数据到c_row
exit when c_job%notfound;--判读是否提取到值,没取到值就退出;取到值c_job%notfound 是false,取不到值是true
dbms_output.put_line(c_row.empno||-||c_row.ename||-||c_row.job||-||c_row.sal);
end loop;
close c_job;
end;

Oracle 游标