失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Oracle 游标使用全解

Oracle 游标使用全解

时间:2020-10-16 22:17:17

相关推荐

Oracle 游标使用全解

数据库|mysql教程

Oracle游标,Oracle 游标使用全解,数据库,Ora

数据库-mysql教程

网站源码有如何制作网站,ubuntu 网易晕音乐,哪个tomcat9支持,国内热门爬虫,php网站开发实用技术教程,滨江seo方案lzw

这个lt;Oracle 游标使用全解gt;文档几乎包含了Oracle游标使用的方方面面,全部通过了测试

左右选择器源码,ubuntu连接共享文件,爬虫抓取内部链接,最简单php,中卫seo外包lzw

端午贺卡源码,电脑vscode如何设置,ubuntu mp3,面试tomcat,SQLite短网址,自适应网页设计的用法,连接数据库字符串,web服务器的主机名,discuz门户编辑器插件,前端h5 video框架,爬虫模板,php 数组追加,seo交流论坛,springboot调用,织梦标题标签语法,div css 网站后台,网页图片100%显示,win8设计模板,dedecms后台登陆验证码错误,php 404页面代码,extjs权限管理系统源码,matlab主程序与源程序lzw

这个文档几乎包含了Oracle游标使用的方方面面,全部通过了测试

— 声明游标;CURSOR cursor_name IS select_statement

–For 循环游标

–(1)定义游标

–(2)定义游标变量

–(3)使用for循环来使用这个游标

declare

–类型定义

cursor c_job

is

select empno,ename,job,sal

from emp

where job=’MANAGER’;

–定义一个游标变量v_cinfo c_emp%ROWTYPE ,该类型为游标c_emp中的一行数据类型

c_row c_job%rowtype;

begin

for c_row in c_job loop

dbms_output.put_line(c_row.empno||’-‘||c_row.ename||’-‘||c_row.job||’-‘||c_row.sal);

end loop;

end;

–Fetch游标

–使用的时候必须要明确的打开和关闭

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

–提取一行数据到c_row

fetch c_job into c_row;

–判读是否提取到值,没取到值就退出

–取到值c_job%notfound 是false

–取不到值c_job%notfound 是true

exit when c_job%notfound;

dbms_output.put_line(c_row.empno||’-‘||c_row.ename||’-‘||c_row.job||’-‘||c_row.sal);

end loop;

–关闭游标

close c_job;

end;

–1:任意执行一个update操作,用隐式游标sql的属性%found,%notfound,%rowcount,%isopen观察update语句的执行情况。

begin

update emp set ENAME=’ALEARK’ WHERE EMPNO=7469;

if sql%isopen then

dbms_output.put_line(‘Openging’);

else

dbms_output.put_line(‘closing’);

end if;

if sql%found then

dbms_output.put_line(‘游标指向了有效行’);–判断游标是否指向有效行

else

dbms_output.put_line(‘Sorry’);

end if;

if sql%notfound then

dbms_output.put_line(‘Also Sorry’);

else

dbms_output.put_line(‘Haha’);

end if;

dbms_output.put_line(sql%rowcount);

exception

when no_data_found then

dbms_output.put_line(‘Sorry No data’);

when too_many_rows then

dbms_output.put_line(‘Too Many rows’);

end;

declare

empNumber emp.EMPNO%TYPE;

empName emp.ENAME%TYPE;

begin

if sql%isopen then

dbms_output.put_line(‘Cursor is opinging’);

else

dbms_output.put_line(‘Cursor is Close’);

end if;

if sql%notfound then

dbms_output.put_line(‘No Value’);

else

dbms_output.put_line(empNumber);

end if;

dbms_output.put_line(sql%rowcount);

dbms_output.put_line(‘————-‘);

select EMPNO,ENAME into empNumber,empName from emp where EMPNO=7499;

dbms_output.put_line(sql%rowcount);

if sql%isopen then

dbms_output.put_line(‘Cursor is opinging’);

else

dbms_output.put_line(‘Cursor is Closing’);

end if;

if sql%notfound then

dbms_output.put_line(‘No Value’);

else

dbms_output.put_line(empNumber);

end if;

exception

when no_data_found then

dbms_output.put_line(‘No Value’);

when too_many_rows then

dbms_output.put_line(‘too many rows’);

end;

–2,使用游标和loop循环来显示所有部门的名称

–游标声明

declare

cursor csr_dept

is

–select语句

select DNAME

from Depth;

–指定行指针,这句话应该是指定和csr_dept行类型相同的变量

row_dept csr_dept%rowtype;

begin

–for循环

for row_dept in csr_dept loop

dbms_output.put_line(‘部门名称:’||row_dept.DNAME);

end loop;

end;

如果觉得《Oracle 游标使用全解》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。