我的存储过正中要循环处理A表(10条记录)的数据,处理时部分记录(如:2、6、8、9条)报错,我想把错误记录的ID字段和处理时的系统时间作为结果集返回到我的C#程序。是不是要定义 ref cursor,怎样往 ref cursor放数据。SQL SERVER 能定义虚拟表,在ORACLE怎么办哪?哪位大侠能举个小例子(存储过程)说明一下?

解决方案 »

  1.   

    不好搞游标还实现不了,使用oracle的类型,又不知道C#支持不?
    你如果只要返回id,你就直接返回一个id的字符串就行了。然后使用你的程序去split下。。
      

  2.   

    如果数据量很小的话可以使用拼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