oracle 游标使用(显式游标)

本文提供了三个使用PL/SQL游标的示例,展示了如何从数据库表中检索并逐行处理数据。这些示例包括基本的游标使用、通过变量获取数据以及使用FOR循环进行迭代。

1.  

Set Serveroutput on;  

declare 
    Cursor tem_cursor is 
           select * from xuesheng xs;
           v_row tem_cursor%rowtype;
begin 
    open tem_cursor;
    loop
         fetch tem_cursor into v_row;
         exit when tem_cursor%NOTFOUND;
         dbms_output.put_line(v_row.xing_ming);
    end loop;
    close tem_cursor;
end;
/

2.

set serveroutput on;
declare
    cursor tmp_cur is
           select xing_ming,yu_wen,shu_xue from xuesheng;
           v_xing_ming xuesheng.xing_ming%type;
           v_yu_wen xuesheng.yu_wen%type;
           v_shu_xue xuesheng.shu_xue%type;
begin
    open tmp_cur;
    loop
         fetch tmp_cur into v_xing_ming,
                            v_yu_wen,
                            v_shu_xue;
         exit when tmp_cur%NOTFOUND;
         dbms_output.put_line(v_xing_ming);
    end loop;
    close tmp_cur;
end;
/

 3.

set serveroutput on;
declare
    cursor tem_cur is
           select xs.xing_ming,xs.yu_wen,xs.shu_xue 
           from xuesheng xs;
begin
    for tem_xs in tem_cur 
    loop
        dbms_output.put_line(tem_xs.xing_ming);
    end loop;
end;
/

 

数据库前面的章节中有。(不喜勿喷哦)

转载于:https://www.cnblogs.com/mrgong/p/3838233.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值