首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

提交数据库后游标继续取值有关问题

2012-07-08 
提交数据库后游标继续取值问题??? 提交了数据库后,游标能否接着取值。??? 实验如下:??? CUSTOMER表:??? CUS

提交数据库后游标继续取值问题

??? 提交了数据库后,游标能否接着取值。

??? 实验如下:

??? CUSTOMER表:

??? CUSTOMERID NAME???????????????? LOCATION
---------- -------------------- --------------------
?????? 201????????? Dennis?????????????? 海淀
?????? 202????????? John????????????????? 朝阳
?????? 203????????? Tom????????????????? 东城
?????? 204???????? ?Jenny??????????????? 东城
?????? 205????????? Rick?????????????????? 西城

??? 存储过程:

 create or replace procedure Hello is        cur_result customer%rowtype;        i number;        cursor cur_select is select CUSTOMERID,NAME,LOCATION from customer;    begin        i := 0;        open cur_select;        dbms_output.put_line('开始');    --第一次循环取值    loop        i := i + 1;        fetch cur_select into cur_result;        if cur_select%notfound then            dbms_output.put_line('exit 第一次取值');            exit;        end if;        dbms_output.put_line('第一次'||i||'='||cur_result.name);        if i = 2 then            dbms_output.put_line('第一次提交'||i||'='||cur_result.name);            commit;            exit;        end if;    end loop;    --第二次循环取值    loop        i := i + 1;        fetch cur_select into cur_result;        if cur_select%notfound then            dbms_output.put_line('exit 第二次取值'');            exit;        end if;        dbms_output.put_line('第二次'||i||'='||cur_result.name);    end loop;    close cur_select;end Hello;/ 

?

???********************************************

结果如下:

开始
第一次1=Dennis
第一次2=John
第一次提交2=John
第二次3=Tom
第二次4=Jenny
第二次5=Rick
exit 第二次取值

********************************************

?

证明,提交了数据库后,没有关闭游标,无需打开,继续可以取值

?

热点排行