存储过程要返回结果集,结果集是在存储过程中自插入的数据,怎么实现?

_三皮_ 2010-12-14 02:47:21
我的存储过正中要循环处理A表(10条记录)的数据,处理时部分记录(如:2、6、8、9条)报错,我想把错误记录的ID字段和处理时的系统时间作为结果集返回到我的C#程序。是不是要定义 ref cursor,怎样往 ref cursor放数据。SQL SERVER 能定义虚拟表,在ORACLE怎么办哪?哪位大侠能举个小例子(存储过程)说明一下?
...全文
92 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
minitoy 2010-12-14
  • 打赏
  • 举报
回复
如果数据量比较大可以使用临时表.
minitoy 2010-12-14
  • 打赏
  • 举报
回复
如果数据量很小的话可以使用拼sql的方法来返回cursor
SQL> create or replace procedure proc_return_error(o_cur out sys_refcursor)
2 as
3 v_sql varchar2(4000);
4 begin
5 v_sql:='select * from (
6 select cast(null as number(20)) id ,cast(null as date) dealdate from dual';

7 for i in 1..10 loop
8 if mod(i,3)=0 then
9 v_sql:=v_sql||' union all select '||i||',sysdate from dual';
10 end if;
11 end loop;
12 v_sql:=v_sql||')where dealdate is not null';
13 open o_cur for v_sql;
14 end;
15 /

Procedure created.

SQL> var cv_a refcursor
SQL> exec proc_return_error(:cv_a);

PL/SQL procedure successfully completed.

SQL> print cv_a

ID DEALDATE
---------- --------------
3 13-12月-10
6 13-12月-10
9 13-12月-10
Oraclefans_ 2010-12-14
  • 打赏
  • 举报
回复
不好搞。。。游标还实现不了,使用oracle的类型,又不知道C#支持不?
你如果只要返回id,你就直接返回一个id的字符串就行了。然后使用你的程序去split下。。
chengfellow 2010-12-14
  • 打赏
  • 举报
回复
把帖子转到ORACLE版问下

17,140

社区成员

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

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