oracle执行存储过程返回多行查询数据?

lctqzq 2008-10-27 06:32:30
CREATE OR REPLACE PROCEDURE proAA
IS
Begin
select * from table1;
End;


Execute proAA;
// 用什么方法实现执行后,显示这条语句(select * from table1)的所有数据出来;
在SQL SERVER2000执行存储过程后会返回多行数据的,在oracle怎么样返回多行查询数据????????
...全文
1893 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
luck512913459 2011-10-10
  • 打赏
  • 举报
回复
一楼的非常正确呀
lctqzq 2008-10-29
  • 打赏
  • 举报
回复
>create or replace procedure test_p(in_var number,out_var out sys_refcursor)
>as
>begin
>open out_var for select * from test where aaa=in_var;
>end;
>/

Procedure created.

>var abc refcursor
>exec test_p(3,:abc)

PL/SQL procedure successfully completed.

>print :abc

执行print出错,什么原因呢?

lctqzq 2008-10-29
  • 打赏
  • 举报
回复
明白了,非常感谢大家的帮忙
hong1987 2008-10-29
  • 打赏
  • 举报
回复
create or replace procedure proAA(out_var out sys_refcursor)
as
begin
open out_var for select * from table1;
end;

调用
declare
v_out sys_refcursor;
begin
proAA(v_out);
end;
codearts 2008-10-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lctqzq 的回复:]
我想要的是,执行存储过程后,将select * from table1的所有字段的数据显示在屏幕;
如果是SQL SERVER2000很容易的就显示到屏幕
[/Quote]

这个在oracle里没有的,oracle要返回数据集,是用out参数的ref cursor来实现的。
google一下相关的文章即可
DongloveRen 2008-10-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lctqzq 的回复:]
我想要的是,执行存储过程后,将select * from table1的所有字段的数据显示在屏幕;
如果是SQL SERVER2000很容易的就显示到屏幕
[/Quote]
楼主,我认为一楼的朋友用游标来解决你的这个问题是可以的,你移动游标前就让其输出,这样能实现你所需的功能
范佩西_11 2008-10-28
  • 打赏
  • 举报
回复
1楼的可以用的。
你直接
declare
CURSOR l_c IS select col1,col2 from table1;
Begin
FOR i IN l_c LOOP
dbms_output.put_line(i.col1||' '||i.col2);
END LOOP;
End;
/

注意要把col1换成你的表的列
lctqzq 2008-10-28
  • 打赏
  • 举报
回复
我想要的是,执行存储过程后,将select * from table1的所有字段的数据显示在屏幕;
如果是SQL SERVER2000很容易的就显示到屏幕
lctqzq 2008-10-28
  • 打赏
  • 举报
回复
楼1,你好像不明白我的意思。用你的方法不是很实用
ITMiner 2008-10-28
  • 打赏
  • 举报
回复
>create or replace procedure test_p(in_var number,out_var out sys_refcursor)
>as
>begin
>open out_var for select * from test where aaa=in_var;
>end;
>/

Procedure created.

>var abc refcursor
>exec test_p(3,:abc)

PL/SQL procedure successfully completed.

>print :abc

返回多行查询数据
BlueskyWide 2008-10-27
  • 打赏
  • 举报
回复
看一下1楼测试的这个例子:
http://topic.csdn.net/u/20081026/21/04c0693f-41df-42fd-ac60-a04122232ac2.html


[Quote=引用楼主 lctqzq 的帖子:]
CREATE OR REPLACE PROCEDURE proAA
IS
Begin
select * from table1;
End;


Execute proAA;
// 用什么方法实现执行后,显示这条语句(select * from table1)的所有数据出来;
在SQL SERVER2000执行存储过程后会返回多行数据的,在oracle怎么样返回多行查询数据????????
[/Quote]
oracledbalgtu 2008-10-27
  • 打赏
  • 举报
回复
sqlplus 下执行:
CREATE OR REPLACE PROCEDURE proAA
IS
CURSOR l_c IS select col1,col2 from table1;
Begin
FOR i IN l_c LOOP
dbms_output.put_line(i.col1||' '||i.col2);
END LOOP;
End;
/

SET serveroutput ON

EXEC proaa;


[Quote=引用楼主 lctqzq 的帖子:]
CREATE OR REPLACE PROCEDURE proAA
IS
Begin
select * from table1;
End;


Execute proAA;
// 用什么方法实现执行后,显示这条语句(select * from table1)的所有数据出来;
在SQL SERVER2000执行存储过程后会返回多行数据的,在oracle怎么样返回多行查询数据????????
[/Quote]

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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