从 oracle 存储过程中获取值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1852855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get value from oracle stored procedure
提问by FlintOff
I have a oracle procedure which should return a concatenated string of all the parameters
我有一个 oracle 程序,它应该返回所有参数的连接字符串
create or replace procedure tin_builder (type in varchar2,
tin_serial in number, rand_digit in varchar2, tin out varchar2 ) is
BEGIN
tin := type || TO_CHAR(tin_serial) || rand_digit ;
END
Now i want to call the procedure from visual studio 2008 (C# code)
现在我想从 Visual Studio 2008(C# 代码)调用该过程
public void TinBuilder(string type, long tin_serial, string rand_digit)
{
OracleConnection connection = new OracleConnection("Data Source=xe;User ID=system;Password=******;");
OracleCommand cmd = new OracleCommand();
cmd.Connection = connection;
cmd.CommandText = "tin_builder";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("type", OracleDbType.Varchar2).Value = type;
cmd.Parameters.Add("tin_serial", OracleDbType.Decimal).Value = tin_serial;
cmd.Parameters.Add("rand_digit", OracleDbType.Varchar2).Value = rand_digit;
cmd.Parameters.Add("tin", OracleDbType.Varchar2).Direction = ParameterDirection.ReturnValue;
try
{
connection.Open();
cmd.ExecuteNonQuery();
TextBox1.Text = cmd.Parameters["tin"].Value.ToString();
}
catch (Exception ex)
{
}
finally
{
connection.Close();
}
}
Then called it with :
然后调用它:
TinBuilder("1", 10000001, "37");
But it does not show any value in the text box :( . Please someone help me out.
但它没有在文本框中显示任何值:(。请有人帮我。
回答by Sandeep
"Type" is a reserved word in Oracle. Here's the link: http://www.cs.umbc.edu/help/oracle8/server.815/a42525/apb.htm
“类型”是 Oracle 中的保留字。这是链接:http: //www.cs.umbc.edu/help/oracle8/server.815/a42525/apb.htm
And as said by OMG Ponies change & try: SELECT type || TO_CHAR(tin_serial) || rand_digit INTO tin FROM DUAL;
正如 OMG Ponies 所说,更改并尝试:选择类型 || TO_CHAR(tin_serial) || rand_digit INTO tin FROM DUAL;
And also make sure you always 'initiate' exception to catch these kind of errors
并确保您始终“启动”异常以捕获此类错误
回答by David Aldridge
"Type" may be a reserved word. Are you sure the procedure compiled and is valid?
“类型”可以是保留字。您确定该程序已编译并且有效吗?
Also are you catching any error messages there, and hiding them with the catch clause? That seems like bad practice.
您是否还在那里捕获任何错误消息,并使用 catch 子句隐藏它们?这似乎是不好的做法。