oracle存储过程的问题——参数
我有这个存储过程:
CREATE OR REPLACE PROCEDURE "LIQUIDACION_OBTENER" (
p_Cuenta IN NUMBER,
p_Fecha IN DATE,
p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE
) IS
BEGIN
SELECT FILADETALLE
INTO p_Detalle
FROM Liquidacion
WHERE (FILACUENTA = p_Cuenta)
AND (FILAFECHA = p_Fecha);
END;
/
...和我的 C# 代码:
string liquidacion = string.Empty;
OracleCommand command = new OracleCommand("Liquidacion_Obtener");
command.BindByName = true;
command.Parameters.Add(new OracleParameter("p_Cuenta", OracleDbType.Int64));
command.Parameters["p_Cuenta"].Value = cuenta;
command.Parameters.Add(new OracleParameter("p_Fecha", OracleDbType.Date));
command.Parameters["p_Fecha"].Value = fecha;
command.Parameters.Add("p_Detalle", OracleDbType.Varchar2, ParameterDirection.Output);
OracleConnectionHolder connection = null;
connection = this.GetConnection();
command.Connection = connection.Connection;
command.CommandTimeout = 30;
command.CommandType = CommandType.StoredProcedure;
OracleDataReader lector = command.ExecuteReader();
while (lector.Read())
{
liquidacion += ((OracleString)command.Parameters["p_Detalle"].Value).Value;
}
问题是,当我尝试将值放入参数“Fecha”(即日期)时,代码给出了此错误(当行 command.ExecuteReader();
已执行)
Oracle.DataAccess.Client.OracleException : ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYSTEM.LIQUIDACION_OBTENER", line 9
ORA-06512: at line 1
我尝试使用日期时间,但不是问题,我已经尝试过不使用输入参数而仅使用输出,但仍然遇到相同的错误。显然问题出在输出参数上。 我已经尝试将 p_Detalle OUT VARCHAR2 而不是 p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE 但它也不起作用
我希望我的帖子是可以理解的.. 谢谢!!!!!!!!!!
I have this stored procedure:
CREATE OR REPLACE PROCEDURE "LIQUIDACION_OBTENER" (
p_Cuenta IN NUMBER,
p_Fecha IN DATE,
p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE
) IS
BEGIN
SELECT FILADETALLE
INTO p_Detalle
FROM Liquidacion
WHERE (FILACUENTA = p_Cuenta)
AND (FILAFECHA = p_Fecha);
END;
/
...and my c# code:
string liquidacion = string.Empty;
OracleCommand command = new OracleCommand("Liquidacion_Obtener");
command.BindByName = true;
command.Parameters.Add(new OracleParameter("p_Cuenta", OracleDbType.Int64));
command.Parameters["p_Cuenta"].Value = cuenta;
command.Parameters.Add(new OracleParameter("p_Fecha", OracleDbType.Date));
command.Parameters["p_Fecha"].Value = fecha;
command.Parameters.Add("p_Detalle", OracleDbType.Varchar2, ParameterDirection.Output);
OracleConnectionHolder connection = null;
connection = this.GetConnection();
command.Connection = connection.Connection;
command.CommandTimeout = 30;
command.CommandType = CommandType.StoredProcedure;
OracleDataReader lector = command.ExecuteReader();
while (lector.Read())
{
liquidacion += ((OracleString)command.Parameters["p_Detalle"].Value).Value;
}
the thing is that when I try to put a value into the parameter "Fecha" (that is a date) the code gives me this error (when the line command.ExecuteReader();
is executed)
Oracle.DataAccess.Client.OracleException : ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYSTEM.LIQUIDACION_OBTENER", line 9
ORA-06512: at line 1
I tried with the datetime and was not the problem, I eve tried with no input parameters and just the output and still got the same error. Aparently the problem is with the output parameter.
I already tried putting p_Detalle OUT VARCHAR2 instead of p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE but it didn't work either
I hope my post is understandable..
thanks!!!!!!!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
输出是什么:
您拥有的输出参数表示法是正确的:
...因此,在将 Oracle 数据类型转换为其 .NET 同级数据类型时,问题将留在 C# 代码中。我以前见过,在使用Java时...
以前
如果
LIQUIDACION.filafecha
的数据类型是VARCHAR2/etc(不是DATE),请使用:...或者您可以将参数更改为匹配数据类型:
...并更正 C# 代码以传递正确的信息。
理想情况下,日期列应该是 DATE 数据类型......
What is the output from:
The out parameter notation you have is correct:
...so that leaves the issue to be in the C# code, when converting the Oracle data type to its .NET sibling. I've seen it before, when using Java...
Previously
If the data type of
LIQUIDACION.filafecha
is VARCHAR2/etc (not DATE), use:...or you could change the parameter to match the data type:
...and correct the C# code to pass the proper information.
Ideally, a date column should be a DATE data type...
可能...这可能是问题所在。尝试使用Oracle to_date函数来匹配日期格式。
如果这不起作用,作为最后的手段,将参数更改为 varchar 并将日期作为字符串传递给存储过程。在 Oracle 中使用 to_date。
这样您的存储过程将是:
Oracle/PLSQL: To_Date Function
Probably... this can be the problem. Try to use Oracle to_date function to match the date format.
If that doesn't work, as a last resort change the parameter to varchar and pass the date as a string to the stored procedure. Use to_date inside Oracle.
This way your stored procedure would be:
Oracle/PLSQL: To_Date Function
设置参数时尝试使用 to_date(p_fecha, 'yyyy-mmm-dd') :
Try to use to_date(p_fecha, 'yyyy-mmm-dd') when setting the parameter:
看来您没有定义输出参数的大小:
我不知道 ADO 默认值是什么,但它显然比
LIQUIDACION.FILADETALLE%TYPE
的长度更小。当接收变量太小或数据类型错误时,Oracle 会抛出 ORA-06502。尝试类似的操作(调整大小以匹配数据库列定义):It appears that you are not defining the size of the output parameter:
I don't know what ADO defaults to, but it is obviously smaller the length of
LIQUIDACION.FILADETALLE%TYPE
. Oracle hurls ORA-06502 when the receiving variable is too small or of the wrong datatype. Try something like (adjusting the size to match the database column definition):