ImageVerifierCode 换一换
格式:DOCX , 页数:9 ,大小:17.26KB ,
资源ID:3670536      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-3670536.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(CH6游标管理Word文档下载推荐.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

CH6游标管理Word文档下载推荐.docx

1、没有找到记录. end if; if not sql%isopen then dbms_output.put_line(sql游标已经关闭 end if; commit;end;/* 显式游标 用户自定义的游标 一般使用步骤: 声明游标: cursor 游标名 is 查询语句 ; 打开游标: open 游标名; 提取游标: fetch 游标名 into 变量; 关闭游标: close 游标名*/declare cursor v_cs is select * from scott.emp; -声明游标 v_temp v_cs%rowtype; open v_cs; -打开游标 loop fetc

2、h v_cs into v_temp; -提取游标 dbms_output.put_line(v_temp.ename | |v_temp.hiredate); exit when v_cs%notfound; -如果游标没有记录退出循环 end loop; close v_cs; -关闭游标-游标属性说明 v_dept number; cursor v_cur is select * from scott.emp where deptno=v_dept; c_temp v_cur%rowtype; v_dept:=30; open v_cur;fetch前游标总记录数:|v_cur%rowc

3、ount); if(v_cur%isopen) then游标已经打开 loop fetch v_cur into c_temp; dbms_output.put(游标总记录数:|v_cur%rowcount| if(v_cur%found) then dbms_output.put_line(c_temp.ename|c_temp.sal);游标已经没有记录 exit; end loop; close v_cur;/*带参数的游标 声明: cursor 游标名(形参 数据类型.) is select. where .=形参; 使用: open 游标名(实参); v_input scott.em

4、p.deptno%type; v_name scott.emp.ename%type; v_sal scott.emp.sal%type; cursor c_cur(v_param number) is select ename,sal from scott.emp where deptno=v_param; v_input:=&部门编号; open c_cur(v_input); -传入实参 fetch c_cur into v_name,v_sal; exit when c_cur%notfound; dbms_output.put_line(v_name|v_sal); close c_

5、cur;用于delete/update的游标 声明时指定 for update of 列 nowait 加行级锁 of 列 如果涉及到多张表,默认会在所有表上加行共享锁,为了只在特定表上加行共享锁,需要在for update子句后带有of子句指定字段名 更新时 update .where current of 游标名declare cursor c_cur is select * from scott.emp for update ; v_temp emp%rowtype; open c_cur; fetch c_cur into v_temp; exit when c_cur%notfoun

6、d; if(v_temp.sal1000) then update scott.emp set sal=sal+1 where current of c_cur; close c_cur; for 循环游标 自动打开,关闭,自动获取记录 cursor cursor_name is select. for v_name in cursor_name(或select语句) loop.end loop;例1 cursor c_cur is select * from scott.emp;begin for v_temp in c_cur loop -v_temp局部变量,无需声明 dbms_outp

7、ut.put_line(v_temp.ename|v_temp.sal); end loop;例2 v_input varchar2(1); v_input:请选择 if v_input=a then for v_rec in (select * from emp) dbms_output.put_line(v_rec.empno|:|v_rec.ename|v_rec.hiredate|v_rec.sal); elsif v_input=b for v_rec in (select * from dept) dbms_output.put_line(v_rec.deptno|v_rec.dn

8、ame);please input. return;/* for 循环游标(带参数) * 声明游标: cursor cursor_name(形参列表) is select. for v_name in cursor_name(实参)*/ v_input emp.deptno%type; cursor c(dept number) is select * from emp where deptno=dept ; for v_rec in c(v_input) loop dbms_output.put_line(v_rec.ename|/* ref cursor游标*用于处理运行时动态执行的 SQ

9、L查询 即在open游标时动态指定sql语句声明ref cursor类型 :TYPE IS REF CURSOR RETURN ; 声明ref游标类型的游标变量: 变量名 游标名; 打开方式: open cursor_name for 查询语句*/声明强类型的 REF 游标:TYPE t_refcur IS REF CURSOR RETURN emp%ROWTYPE;V_cur t_refcur;声明弱类型的 REF 游标 (用于动态SQL) TYPE t_refcur IS REF CURSOR; type v_refcur is ref cursor; - -声明 ref cursor 类

10、型 refcur v_refcur; -声明 ref cursor 类型的游标变量 v_id number; v_name varchar2(20); v_selection varchar2(1):=upper(substr(请输入员工(E)或部门编号(D),1,1); begin if v_selection=E open refcur for select empno,ename from emp; -打开游标=员工信息= elsif v_selection=D open refcur for select deptno,dname from dept;=部门信息=请输入员工信息(E)或

11、部门信息(D) - 返回 fetch refcur into v_id,v_name;- 提取游标 while refcur%found loop#|v_id|v_name); close refcur; - 关闭游标/*动态SQL(使用ref cursor 返回多行记录)* 使用占位符 Open cursor_name for v_sql using 占位符对应的变量*/ v_cur v_refcur; v_emp emp%rowtype; v_salary number; v_sql varchar2(100); v_dno number; v_salary :请输入薪水标准 v_dno:请输入部门编号 v_sql:select * from emp where sal1 and deptno=:2 order by sal desc open v_cur for v_sql using v_salary,v_dno;薪水大于|v_salary |的员工: fetch v_cur into v_emp; exit when v_cur%notfound;姓名:|v_emp.ename| 薪水:|v_emp.sal);

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2