在PL/SQL中怎样执行存储过程

pbmiyuki 2006-11-13 03:17:54
我写了一个返回结果集的存储过程:如下
建一个程序包:
CREATE OR REPLACE PACKAGE TESTPACKAGE AS
TYPE Test_CURSOR IS REF CURSOR;
end TESTPACKAGE;

建立存储过程,存储过程为:
create or replace procedure test_select(out_select out testpackage.Test_CURSOR) is
begin
open out_select for select * from test ;
end test_select ;

以上编译通过
然后在pl/sql中执行这个存储过程:
declare
out_select testpackage.test_cursor ;
begin
test_select(out_select) ;
dbms_output.put_line(out_select);
end ;
出现编译错误,请问哪里错了
...全文
711 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbmiyuki 2006-11-14
  • 打赏
  • 举报
回复
楼上的,谢了
kawentea 2006-11-14
  • 打赏
  • 举报
回复
declare
out_select testpackage.test_cursor;
ceshi test%rowtype;
begin
test_select(outcur);
loop
exit when outcur%notfound;
fetch outcur into ceshi;
dbms_output.put_line(ceshi.ename);
end loop;
end;

更正补充说明:上面变量定义随意取名,其中ceshi.ename也是随便写的,也就是说你必须的输出游标里的内容,不能直接输出游标。ename是字段名。
kawentea 2006-11-14
  • 打赏
  • 举报
回复
declare
out_select testpackage.test_cursor;
ceshi emp%test;
begin
test_select(outcur);
loop
exit when outcur%notfound;
fetch outcur into ceshi;
dbms_output.put_line(ceshi.ename);
end loop;
end;
pbmiyuki 2006-11-14
  • 打赏
  • 举报
回复
在程序中调用这个存储过程我已经做出来了,我现在问的是在"PL/SQL中"能不能显示这个结果集?
怎样显示?
tdaly 2006-11-14
  • 打赏
  • 举报
回复
游标不可以作为参数传啊。
我们写程序调用存储过程的时候,游标参数都是不写的啊。
wangzk0206 2006-11-13
  • 打赏
  • 举报
回复
declare
out_select testpackage.test_cursor ;
begin
test_select(out_select) ;
dbms_output.put_line(out_select);
end ;

这个你是用来干什么???

一个test_select 不就实现了你的用法吗
为什么还要把游标作为输出参数那?
pbmiyuki 2006-11-13
  • 打赏
  • 举报
回复
没人知道吗,高手啊!!!!!!!!
pbmiyuki 2006-11-13
  • 打赏
  • 举报
回复
declare
ret testpackage.Test_CURSOR%type ;
begin
test_select(ret) ;
dbms_output.put_line(ret);
end ;
还是不对,报错为

ORA-06550: 第 2 行, 第 9 列:
PLS-00206: %TYPE 必须用于变量, 列, 字段或属性, 而不是 'TESTPACKAGE.TEST_CURSOR'
ORA-06550: 第 2 行, 第 9 列:
PL/SQL: Item ignored
ORA-06550: 第 4 行, 第 17 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 4 行, 第 5 列:
PL/SQL: Statement ignored
ORA-06550: 第 5 行, 第 26 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 5 行, 第 5 列:
PL/SQL: Statement ignored
xuwm 2006-11-13
  • 打赏
  • 举报
回复
是不是应该:
declare
out_select testpackage.test_cursor%type ;
begin

end ;
另外dbms_output.put_line可以直接输出out_select ,有点多态的感觉啊。

pbmiyuki 2006-11-13
  • 打赏
  • 举报
回复
有什么问题?是变量名写法错了吗还是类型有问题?
tongyu10068 2006-11-13
  • 打赏
  • 举报
回复
我觉得你的out_select变量定义的有问题
pbmiyuki 2006-11-13
  • 打赏
  • 举报
回复
在线等

17,377

社区成员

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

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