oracle存储过程的问题——参数

发布于 2024-08-27 11:53:45 字数 1690 浏览 8 评论 0原文

我有这个存储过程:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水水月牙 2024-09-03 11:53:45

输出是什么:

DESC LIQUIDACION

您拥有的输出参数表示法是正确的:

p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE

...因此,在将 Oracle 数据类型转换为其 .NET 同级数据类型时,问题将留在 C# 代码中。我以前见过,在使用Java时...

以前


如果LIQUIDACION.filafecha的数据类型是VARCHAR2/etc(不是DATE),请使用:

SELECT la.filadeetaile
  INTO p_Detalle
  FROM LIQUIDACION la
 WHERE la.filacuenta = p_Cuenta
   AND la.filafecha = TO_CHAR(p_Fecha, 'YYYY-MON-DD');

...或者您可以将参数更改为匹配数据类型:

p_Fecha IN LIQUIDACION.filafecha%TYPE

...并更正 C# 代码以传递正确的信息。

理想情况下,日期列应该是 DATE 数据类型......

What is the output from:

DESC LIQUIDACION

The out parameter notation you have is correct:

p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE

...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:

SELECT la.filadeetaile
  INTO p_Detalle
  FROM LIQUIDACION la
 WHERE la.filacuenta = p_Cuenta
   AND la.filafecha = TO_CHAR(p_Fecha, 'YYYY-MON-DD');

...or you could change the parameter to match the data type:

p_Fecha IN LIQUIDACION.filafecha%TYPE

...and correct the C# code to pass the proper information.

Ideally, a date column should be a DATE data type...

雨落□心尘 2024-09-03 11:53:45

可能...这可能是问题所在。尝试使用Oracle to_date函数来匹配日期格式。

如果这不起作用,作为最后的手段,将参数更改为 varchar 并将日期作为字符串传递给存储过程。在 Oracle 中使用 to_date。

这样您的存储过程将是:

CREATE OR REPLACE PROCEDURE "LIQUIDACION_OBTENER" (
p_Cuenta IN NUMBER, 
p_Fecha IN VARCHAR,
p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE
) IS

BEGIN 

    SELECT 
        FILADETALLE
    INTO
        p_Detalle
    FROM 
        Liquidacion
    WHERE 
        (FILACUENTA = p_Cuenta)
        AND (FILAFECHA = to_date(p_Fecha, 'yyyy-MON-dd'));

END;

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:

CREATE OR REPLACE PROCEDURE "LIQUIDACION_OBTENER" (
p_Cuenta IN NUMBER, 
p_Fecha IN VARCHAR,
p_Detalle OUT LIQUIDACION.FILADETALLE%TYPE
) IS

BEGIN 

    SELECT 
        FILADETALLE
    INTO
        p_Detalle
    FROM 
        Liquidacion
    WHERE 
        (FILACUENTA = p_Cuenta)
        AND (FILAFECHA = to_date(p_Fecha, 'yyyy-MON-dd'));

END;

Oracle/PLSQL: To_Date Function

我ぃ本無心為│何有愛 2024-09-03 11:53:45

设置参数时尝试使用 to_date(p_fecha, 'yyyy-mmm-dd') :

  command.Parameters["p_Fecha"].Value = to_date(fecha, 'yyyy-MON-dd');

Try to use to_date(p_fecha, 'yyyy-mmm-dd') when setting the parameter:

  command.Parameters["p_Fecha"].Value = to_date(fecha, 'yyyy-MON-dd');
挽心 2024-09-03 11:53:45

看来您没有定义输出参数的大小:

command.Parameters.Add("p_Detalle", OracleDbType.Varchar2, ParameterDirection.Output);            

我不知道 ADO 默认值是什么,但它显然比 LIQUIDACION.FILADETALLE%TYPE 的长度更小。当接收变量太小或数据类型错误时,Oracle 会抛出 ORA-06502。尝试类似的操作(调整大小以匹配数据库列定义):

command.Parameters["p_Detalle"].Size = 20;

It appears that you are not defining the size of the output parameter:

command.Parameters.Add("p_Detalle", OracleDbType.Varchar2, ParameterDirection.Output);            

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):

command.Parameters["p_Detalle"].Size = 20;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文