如何在oracle中返回多条记录?

kanying 2003-08-18 04:34:25
我现有一个表A,表中含有多条记录,欲从中选择满足某一条件(例如:年龄为18)的多条记录返回。请问用存储过程或函数如何编写?编好后如何调用?
...全文
38 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
logzgh 2003-08-20
  • 打赏
  • 举报
回复
beckhambobo(beckham):

这样建立的存储过程,界面调用得到的数据显示出来时,要一条一条取吗?

也就是说界面显示这个结果集时该怎么处理?
kanying 2003-08-20
  • 打赏
  • 举报
回复
你好!按照你所教方法,我在sql*plus worksheet中执行了一段代码,提示:pl/sql过程已成功完成。但是我又如何看到记录集中的返回值呢?我通过print语句想显示查询结果,但提示有错。请问要实现这一功能该怎么办?
beckhambobo 2003-08-19
  • 打赏
  • 举报
回复
declare
w_rc pkg_test.myrctype;
w_id student.id%type;
w_name student.name%type;
w_sex student.sex%type;
w_address student.address%type;
w_postcode student.postcode%type;
w_birthday student.birthday%type;
begin
get('1',w_rc);
loop
fetch w_rc into w_id,w_name,w_sex,w_address,w_postcode,w_birthday;
exit when w_rc%notfound;
dbms_output.put_line(w_name);
end loop;
end;
/
kanying 2003-08-19
  • 打赏
  • 举报
回复
非常感谢!过程我是建立成功了,可是像这种类型的过程我应该如何调用,查看其结果呢?
beckhambobo 2003-08-18
  • 打赏
  • 举报
回复
CREATE OR REPLACE PACKAGE pkg_test
AS
TYPE myrctype IS REF CURSOR;
END pkg_test;
/

create PROCEDURE get(p_age NUMBER, p_rc OUT pkg_test.myrctype)
IS
sqlstr VARCHAR2 (500);
BEGIN
sqlstr:='select id,name,sex,address,postcode,birthday
from student where age='||p_age;
OPEN p_rc FOR sqlstr;
END get;
Michaelyfj 2003-08-18
  • 打赏
  • 举报
回复
用数组也可以
mayali 2003-08-18
  • 打赏
  • 举报
回复
要用游标。
lf43 2003-08-18
  • 打赏
  • 举报
回复
帮你顶,我也有类似问题要问

17,086

社区成员

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

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