用oracle的存储过程返回一个查询的结果集

徒步-天下 2009-07-21 12:20:35
再sql中

Create procedure getall
select * from table1.

在Oracle中怎么写
请各位指教,能写全最好。
谢谢

...全文
25698 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
csuxp2008 2009-07-23
  • 打赏
  • 举报
回复
1.如果是在pl/sql块中,实现方法如3楼
2.如果是在sql*plus环境下,就如8楼
wangsong145 2009-07-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 wuchanghao112215 的回复:]
再sql中
SQL codeCreateprocedure getallselect*from table1.
在Oracle中怎么写
请各位指教,能写全最好。
谢谢


[/Quote]
create procedure p(my_cur out sys_refcursor) as
begin
open my_cur for
select * from emp;
end;
rockywu 2009-07-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 quiettown 的回复:]
简单一点吧
SQL codecreateorreplaceprocedure p_test(p_cur out sys_refcursor)asbeginopen p_curforselect*from emp;end p_test;
[/Quote]
不错...这样最方便不过了
quiettown 2009-07-21
  • 打赏
  • 举报
回复
简单一点吧

create or replace procedure p_test(p_cur out sys_refcursor)
as
begin
open p_cur for select * from emp;
end p_test;
robin_ares 2009-07-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jane_64 的回复:]
create or replace Package SYSBasic
as
  type cc_cursor is ref cursor;
end SYSBasic;

CREATE OR REPLACE PROCEDURE getall(
    c_CurSor OUT SYSBASIC.cc_CURSOR  --光标结果
)
begin
  open c_CurSor For
    select * from table1;
end getall;


[/Quote]
up

test_cur SYSBASIC.cc_CURSOR ;
getall(test_cur );
这时就有值了
Jane_64 2009-07-21
  • 打赏
  • 举报
回复
create or replace Package SYSBasic
as
type cc_cursor is ref cursor;
end SYSBasic;

CREATE OR REPLACE PROCEDURE getall(
c_CurSor OUT SYSBASIC.cc_CURSOR --光标结果
)
begin
open c_CurSor For
select * from table1;
end getall;

徒步-天下 2009-07-21
  • 打赏
  • 举报
回复
各位高手来指教下,急着用。非常感谢
xiesongque 2009-07-21
  • 打赏
  • 举报
回复
测试4楼8楼的,运行成功!学习!!!
阿三 2009-07-21
  • 打赏
  • 举报
回复
http://space.itpub.net/67668/viewspace-604908
看看这个
徒步-天下 2009-07-21
  • 打赏
  • 举报
回复
自己顶下
quiettown 2009-07-21
  • 打赏
  • 举报
回复
set serverout on
徒步-天下 2009-07-21
  • 打赏
  • 举报
回复
declare 
test_cur SYSBASIC.cc_CURSOR;
bm SSFJ.BM%TYPE;
mc SSFJ.MC%TYPE;
begin
getfj(test_cur);
loop
fetch test_cur into bm,mc;
exit when test_cur%notfound;
dbms_output.put_line('编码:'||bm);
end loop;
end;

是这样吗?这样只显示anonymous block completed
我是菜鸟什么都不懂请指教
suncrafted 2009-07-21
  • 打赏
  • 举报
回复
在sqlplus界面:
1、var r refcursor;
2、exec p_test(:r);
3、print r;
Jane_64 2009-07-21
  • 打赏
  • 举报
回复
3楼说了啊
徒步-天下 2009-07-21
  • 打赏
  • 举报
回复
那请问,怎样运行查看结果

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧