您的位置:首页 > 数据库 > Oracle

oracle游标的使用

2015-03-24 16:41 435 查看


oracle游标的使用

举报|2012-10-22
17:03zhzengyuan | 分类:数据库DB | 浏览484次
①创建一个包,在该包中定义类型test_cursor是个游标
Create or replace package tespackage as
Type test_cursor is ref cursor;
End tespackage;
①    创建过程:
Create or replace procedure sp_pro10
(spno in number,p_cursor out tespackage.test_cursor) is
Begin
Open p_cursor for select * from emp where deptno=spno;
End sp_pro10; 
如何在sqlplus中调用此过程exec sp_pro10(?,?)第二个参数如何写呢?我想获取emp表中的部门号为10的所有记录。

我有更好的答案|搜索相关资料

加粗

飘红

符号

编号

排版

图片

地图

代码

提交回答匿名

分享到:



按默认排序 | 按时间排序


2条回答

2012-10-22 20:25热心网友

第二个参数声明一个 ref 游标作为参数传进去,存储过程执行完毕以后,直接读取该游标的内容就行了
declare
    cur testpackage.test_cursor;
    rt_emp rowtype%emp;
begin
    sp_pro10(10, cur);
    fetch cur into rt_emp;
    exit when cur%notfound;
        -- 做你的操作
end;



oracle游标的使用

举报|2012-10-22
17:03zhzengyuan | 分类:数据库DB | 浏览484次
①创建一个包,在该包中定义类型test_cursor是个游标
Create or replace package tespackage as
Type test_cursor is ref cursor;
End tespackage;
①    创建过程:
Create or replace procedure sp_pro10
(spno in number,p_cursor out tespackage.test_cursor) is
Begin
Open p_cursor for select * from emp where deptno=spno;
End sp_pro10; 
如何在sqlplus中调用此过程exec sp_pro10(?,?)第二个参数如何写呢?我想获取emp表中的部门号为10的所有记录。

我有更好的答案|搜索相关资料

加粗

飘红

符号

编号

排版

图片

地图

代码

提交回答匿名

分享到:



按默认排序 | 按时间排序


2条回答

2012-10-22 20:25热心网友

第二个参数声明一个 ref 游标作为参数传进去,存储过程执行完毕以后,直接读取该游标的内容就行了
declare
    cur testpackage.test_cursor;
    rt_emp rowtype%emp;
begin
    sp_pro10(10, cur);
    fetch cur into rt_emp;
    exit when cur%notfound;
        -- 做你的操作
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: