简体   繁体   English

从C#调用Oracle中的存储过程

[英]Call stored procedures in Oracle from C#

I have a page with a textbox that passed a value through a stored procedure in Oracle. 我有一个带有文本框的页面,该文本框通过Oracle中的存储过程传递值。 the procedure got changed so, there are now 2 parameters, one for the input value and a second one that returns an integer value back. 程序改变了,现在有2个参数,一个用于输入值,另一个用于返回一个整数值。

Here is the Oracle procedure: 这是Oracle程序:

procedure UnoxDataFix(p_shpmt_nbr in pkms.asn_hdr.shpmt_nbr%type, retval out integer) is
  begin
  retval:=0;
    for r in (
        -- simple select statement
        )
    loop    
     if(r.stat_code = 10 and r.whse_xfer_flag = 'Y')
     then     
        update pkms.asn_dtl ad 
          -- simple set statement
        update pkms.asn_hdr ah
          -- simple set statement
          where ah.shpmt_nbr = p_shpmt_nbr
           RETURNING 1 into retval;
        commit;   
      end if;    
    end loop;
  end;

And here is the core C# code I had: 这是我拥有的核心C#代码:

this.oraServer.ExecuteNonQuery(this.connectionString, CommandType.Text, "begin INTEGRATION.UnoxDataFix('" + input + "'); end;");

The connection string works. 连接字符串有效。 It's just the actual procedure that is giving the error. 这只是给出错误的实际过程。 The 'input' value is the actual value that is sent to the procedure. 'input'值是发送给过程的实际值。 But for returning the 'retval' back to the site, I'm not sure how to. 但是为了让'retval'回到网站,我不知道该怎么做。 I have tried Googling what I can, but it doesn't help. 我已经尝试使用谷歌搜索,但它没有帮助。 I'm a little slow, so all comments are most welcome. 我有点慢,所以所有评论都是最受欢迎的。 :) :)

Because the procedure now expects 2 parameters, you need to give 2 parameters and not only the input parameter. 由于该过程现在需要2个参数,因此您需要提供2个参数而不仅仅是输入参数。 Also, I prefer to use bind variables to prevent sql injection. 另外,我更喜欢使用绑定变量来防止sql注入。 (Yes, you can also use a bind variable for the OUT parameter). (是的,您也可以为OUT参数使用绑定变量)。

begin INTEGRATION.UnoxDataFix(:input, :retval); end;

I am not familiar with the specifics of C#, so I can't help you with the exact methods to use to insert and retrieve the values. 我不熟悉C#的细节,所以我无法帮助您使用插入和检索值的确切方法。

On a side note, what kind of naming convention is this? 另外,这是什么样的命名约定? Are you aiming for unreadability? 你的目标是不可读吗? :) :)

pkms.asn_hdr.shpmt_nbr pkms.asn_hdr.shpmt_nbr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM