免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1402 | 回复: 1
打印 上一主题 下一主题

请教关于游标变量和游标表达式的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-20 14:34 |只看该作者 |倒序浏览
大家好:
      以下PL/SQL程序代码,使用到了指针游标变量:empcur 和 游标表达式:cursor(select ename,sal from emp where deptno=a.deptno)
请问为何指针游标变量empcur在代码中没有使用到open empcur for 指定打开的select结果集语句,而且可以将别的游标数据(dept_cursor)直接into到该游标(empcur):fetch dept_cursor into v_dname,empcur;

游标变量不是要在open语句打开游标时,指定查询结果集才行的吗?怎么在这里可以直接保存dept_cursor游标的数据的?
cursor(select ename,sal from emp where deptno=a.deptno)这个游标表达式和游标变量empcur有什么关系呢?为什么游标empcur 可以保存游标表达式cursor(select ename,sal from emp where deptno=a.deptno)中的ename,sal列的数据: fetch empcur into v_ename,v_sal ??
是不是游标变量empcur 被隐含定义为cursor(select ename,sal from emp where deptno=a.deptno)这个游标变量的别名,所以可以直接引用empcur这个游标变量,而不用先open empcur for select ....了?
由于书上没有说明到这些,还望各位高手能详细指点,谢谢!

declare
  type refcursor is ref cursor;
  cursor dept_cursor(no number) is
    select a.dname,cursor(select ename,sal from emp where deptno=a.deptno)
    from dept a where a.deptno=no;
  empcur refcursor;
  v_dname dept.dname%type;
  v_ename emp.ename%type;
  v_sal emp.sal%type;
begin
  open dept_cursor(&no);
  loop
    fetch dept_cursor into v_dname,empcur;
    exit when dept_cursor%notfound;
    dbms_output.put_line('部门名:'||v_dname);
    loop
      fetch empcur into v_ename,v_sal;
      exit when empcur%notfound;
      dbms_output.put_line('雇员名:'||v_ename||',工资:'||v_sal);
    end loop;
  end loop;
  close dept_cursor;
end;

论坛徽章:
0
2 [报告]
发表于 2012-03-23 17:12 |只看该作者
进来学习的~~~~~~~~~~~
















Signature------------------------------------------------------
We hope to get a long, Steady Business with all Sorts of buyers all over the World.
Christian Louboutin Daffodile
Christian Louboutin Flats  
Christian Louboutin Pumps
Christian Louboutin Sandals


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP